Tag: uitableview

使用委托从button传递信息突出显示单元格

我有一个父视图控制器和一个子视图控制器,我需要将信息从子视图控制器中的button传回到父视图控制器,以便正确的tableViewCell文本被高亮显示。 在父视图控制器中,单击单元格时,单元格文本将突出显示,并且子视图控制器会在屏幕上popup并播放选定的歌曲。 但是,在子视图控制器中有一个向后跳过并跳过前进button,所以当按下其中任何一个button并且再次显示父视图控制器时, 单元格文本现在需要突出显示与之前突出显示的单元格不同的单元格 。 所以我已经为每个视图控制器添加了适当的委托样板代码,但我不确定从子视图控制器获取的最佳信息以发回到父视图控制器,以及如何使用它。 子视图控制器 : -(IBAction)indexChanged:(UISegmentedControl *)sender { NSURL *musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Blip_Select" ofType:@"wav"]]; AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil]; switch (self.segmentedControl.selectedSegmentIndex) { case 0: [click play]; [click play]; [musicPlayer skipToPreviousItem]; break; case 1: [click play]; if ([musicPlayer playbackState] == MPMusicPlaybackStatePlaying) { [musicPlayer pause]; } else { [musicPlayer play]; […]

UITableViewCell中的UIScrollView – 水平滚动

我一直试图在自定义的UITableViewCell设置一个UIScrollView 。 我已经尝试在自定义的.xib文件中添加一个UIScrollView ,对它进行子类化,并手动将其作为子视图添加到cellForRowAtIndexPath方法中的UITableViewCell中。 在所有这些中,我已经在cellForRowAtIndexPath设置了UIScrollView的contentSize 。 但是不pipe怎样,我一直无法水平滚动。 这里有一些代码给你一个想法。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"Custom_Cell"; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { CellIdentifier = @"Custom_Cell"; } CustomCell *cell = (CustomCell *)[self.fpTable dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:nil options:nil]; // cell = [nib objectAtIndex:0]; for(id currentObject in […]

如果我做insertRowsAtIndexPaths UITableView闪烁

我正在使用insertRowsAtIndexPaths方法将行添加到UITableView 。 我把这个代码放在[myTable beginUpdates]; 和[myTable endUpdates]; 。 问题是我的表闪烁,然后滚动到最后一行? 可能是什么问题? 如果我评论[myTable beginUpdates]; 和[myTable endUpdates]; :那么它工作正常。 提前致谢 !!! 这是我的代码: #pragma mark – NSFetchResultController – (void)setFetchedResultsController:(NSFetchedResultsController*)fetchedResultsController { _fetchedResultsController = fetchedResultsController; fetchedResultsController.delegate = self; [fetchedResultsController performFetch:NULL]; } – (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [tblComments beginUpdates]; } – (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { switch (type) { case NSFetchedResultsChangeInsert: […]

如何自定义滑动UITableViewCell时显示的删除button

我有一个表视图,并通过提供一个空的实现- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath表视图控制器的- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath来启用滑动删除function。 当我滑动表格单元格时,我可以看到一个红色的“删除”button。 但是,尽pipe系统语言环境不是英语,但button的标签是“删除”。 我也有问题。 1.我想要删除button根据区域设置本地化。 2.我想添加一些其他的button,就像在苹果的播客应用程序。

dynamic单元高度自动布局IOS

我一直在按照本教程来实现dynamic单元格高度。 dynamic表视图单元格高度但它只适用于我的ios 7,而不是在ios 8中。但它在ipad上工作在ios 8,所以我有点难倒为什么它不能在iphone 。 虽然我完全遵循了代码,但教程和实现方式之间存在一些差异,因为我对自动布局和表格不够了解,所以我不确定这是否是导致我的问题的原因。 首先在教程中,tableView的尾部和前沿完全等于0到超级视图。 在我的实现中,我创build了比例约束,以便在多个不同的布局中缩放tableView。 进一步解释: 这是我的TableView使用多个不同设备的比例约束的图片。 为了实现这一点,我实施了以下限制: 是否有可能的细胞高度不能通过AutoLayout来计算,因为tableView有一个dynamic的高度? 在我的实现和教程之间可以看到的第二个区别是数据源。 我从调用SLQ3Lite数据库中获取数据,而本教程从XML源中获取数据。 我相信数据填充的单元格,因为当我看着我在IPAD上的实现,我可以看到这样的数据: 但在iPhone上,这是显示:表是可见的,但没有单元格被写入到表中。 当我使用debugging器时,我可以看到正在成功从数据库中检索到logging,但是它们没有被写入到表中。 这是很长的代码(对不起) #import "favouritedViewController.h" #import "DBManager.h" #import "favouritedCell.h" @interface favouritedViewController () @property (strong, nonatomic) IBOutlet UITableView *tableView; @property (strong, nonatomic) NSArray *favourites; @property (nonatomic, strong) DBManager *dbManager; typedef void (^CompletionBlock)(); -(void)loadData; -(void)reloadDataWithCompletions:(CompletionBlock)completionBlock; @end @implementation favouritedViewController – (void)viewDidLoad { […]

iOS UITableView单元格滚动后加载不正确?

我在视图中有2个UITableView,我只在第2行第5行和第7行添加了UITableViewCellAccessoryDisclosureIndicator。 但滚动第二张表(第一行消失),然后滚动回顶部(哪一行出现),第一行现在有UITableViewCellAccessoryDisclosureIndicator ?! 第1行莫名其妙地变成了第5行还是第7行? 以下是我的代码cellForRowAtIndexPath: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.textColor = [UIColor blueColor]; cell.detailTextLabel.textColor = [UIColor blackColor]; if (tableView == table1) { cell.textLabel.text = [title1 objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [list1 […]

如何使用NSUserDefaults保存来自ViewController的数据,并在应用程序重新运行时将其检索到TableViewController

我绝望了,一直在解决这个问题。所以我有一个类“WishListItem”,一个TableViewController和一个ViewController。 我在保存数据块和从TableViewController检索它有困难? 如何有效地做到这一点? 我要粘贴所有的代码,因为我不知道是否有重要的东西必须包括在我的问题。 所以我很抱歉,请耐心等待。 这里是。 ViewController.h: #import <UIKit/UIKit.h> #import "WishlistItem.h" @interface JLSViewController : UIViewController @property (strong, nonatomic) IBOutlet UIBarButtonItem *addWishListButton; @property (strong, nonatomic) IBOutlet UITextField *wishTextField; @property (strong, nonatomic) IBOutlet UITextField *descTextField; @property (strong, nonatomic) IBOutlet UIDatePicker *targetDatePicker; @property WishlistItem *wishItem; @end ViewController.m #import "JLSViewController.h" #import "WishlistTableViewController.h" @interface JLSViewController () @property NSMutableArray *wishlistItem; @end […]

UITableViewCell中的UILabel可以创build一个自定义的单元格,而不需要创build单独的类

在我的表格视图单元格中,我需要显示我的数组元素的内容在一个单元格中,如果我插入任何新的内容,以前的内容不会被覆盖。以前的内容和我的新内容应按顺序显示。这里是我的代码 – (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *arrMain=[NSMutableArray arrayWithObjects: cnfqty, cnftitle, cnfrate, nil]; finarray=[[NSMutableArray alloc]init]; [finarray addObjectsFromArray:arrMain]; NSLog(@"%@",finarray); } – (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } #pragma mark – Table view data source – […]

获取json对象,然后分配给可用视图

那么在我的应用程序,我有一个tableview。 我想要做的是:通过Web获取数据,将它们存储在一个数组中,然后根据每个索引的值获取相应的行来获取背景。 我的意思是这样的:如果data [0] = red —> 0行的图像是红色的,否则是绿色的。 我已经设法下载数据,但问题是图像先分配,然后发生http请求。 例如:这是我的代码获取数据并将其存储到数组: – (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"connectionDidFinishLoading"); NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]); // convert to JSON NSError *myError = nil; NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError]; colours== [NSMutableArray array]; NSString *parsed_data=[res objectForKey:@"data_1"]; NSLog(@"getting colour : %@",parsed_data); [colours addObject:parsed_data]; ….. [self.mapMain reloadData]; } mapMain是我的IBoutlet。 并设置背景: […]

根据在swift中select的第一个表格行更改第二个表格内容

我有一个视图与两个表(propertyTypeList&propertyDetailList)和一个文本视图(propertyDetailView) 我想要做的是有propertyDetailList填充基于在propertyTypeList中作出的select的数组,然后有propertyDetailView根据propertyDetailList中的select填充。 我可以使用我的底部函数和indexPath.row查看当前选定的行,但是我无法获得该函数在上面的函数中工作。 这里是我的代码: class NewProjectView: UIViewController { @IBOutlet weak var propertyTypeList: UITableView! @IBOutlet weak var propertyDetailList: UITableView! @IBOutlet weak var propertyDetailView: UITextView! var testarray = ["test1", "test2"] func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { if tableView == propertyTypeList { return projectSources.count; } else { return testarray.count } } func tableView(tableView: UITableView!, cellForRowAtIndexPath […]