Tag: uitableview

正在调用cellForRowAtIndexPath:有没有实际的?

我在实现UITableViewDelegate和UITableViewDataSource直接调用cellForRowAtIndexPath:见过许多开发人员: 1)检索单元格以获取它们存储在单元格中的模型元素: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath]; int secretCode = cell.secretCode; LaunchMissileViewController *vc = [[LaunchMissileViewController alloc] initWithSecretCode:secretCode]; [self.navigationController pushViewController:vc]; } 2)试图devise细胞(这有明确的问题,但似乎很常见): MyCell *cell = (MyCell *)[self cellForRowAtIndexPath:indexPath]; // or [tableView cellForRowAtIndexPat:indexPath]; cell.backgroundColor = [UIColor greenColor]; “只有框架应该调用cellForRowAtIndexPath: ”这个覆盖语句是否安全? 或者有没有一个人可能会自称的实际理由?

如何在tableView中findtapPath的附件button

我有一个简单的UITableView和几行。 当用户点击单元格附件button时(与detailsSegue连接),我想知道单元格是哪一行,所以我可以从我的数组中select正确的对象,并将它分配给下一个视图的variables。 我已经使用委托方法tableview:accessoryButtonTappedForRowWithIndexPath:和分配indexPath值到我的私有财产myRow 。 比在prepareForSegue:sender:方法我用我self.myRow.row值从数组中select正确的对象。 我的问题是,这两个方法似乎执行错误的顺序。 从NSLog中我可以看到prepareForSegue:sender:方法首先被执行,而我的委托方法正在改变self.myRow值。 所以prepareForSegue:sender:方法总是把错误的对象传递给下一个视图(之前被点击过的视图)。 对不起,我的英文家伙。 提前感谢您的帮助。 -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { self.myRow = indexPath; NSLog(@"tapped button at row: %i",self.myRow.row); } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"addSegue"]) { AddViewController *avc = segue.destinationViewController; avc.delegate = self; } else if ([segue.identifier isEqualToString:@"detailsSegue"]) { NSLog(@"Segue row: %i",self.myRow.row); Annotation *annotation = [self.viewsList objectAtIndex:self.myRow.row]; NSLog(@"Segue annotation object: […]

滚动时在UITableView中重复数据

我使用波纹pipe代码来显示TableView上的数据,但滚动时,数据重复和其他数据丢失。 – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [FileCompletedArray count]; } cellForRowatindexpath(): – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; UILabel *FileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, […]

cellForRowAtIndexPath内存pipe理

所以,这是我的cellForRowAtIndexPath的代码: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"]autorelease]; } NSInteger artistIndex = 1; // 1 NSInteger albumIndex = 3; // 3 NSInteger dateIndex = 6; // 6 NSInteger imageIndex = 8; // 5 // ARTIST CGRect frame = CGRectMake(59, […]

UITableViewCell上的UILongPressGestureRecognizer – 双重调用

我在单元格中使用UILongPressGestureRecognizer。 我需要的是:当用户点击一个单元格1.0秒,调用一个视图控制器。 如果用户点击该单元,则另一个VC。 我可以通过使用UILongPressGestureRecognizer来完成。 但问题是,调用viewController两次。 码: if (indexPath.section == 0 && indexPath.row == 1){ UILongPressGestureRecognizer *longPressTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(memberListWithSearchOptions)]; longPressTap.minimumPressDuration = 1.0; [cell addGestureRecognizer:longPressTap]; [longPressTap release]; } 我认为我需要的是在识别LongPress之后,禁用识别器,直到tableView再次出现在屏幕上。 我怎样才能做到这一点? 谢谢, RL

迅速ios添加无限滚动分页到uitableview

我不知道如果tableview有任何内置函数来添加无限滚动/分页。 现在我的VC看起来像这样: var data: JSON! = [] override func viewDidLoad() { super.viewDidLoad() //Init start height of cell self.tableView.estimatedRowHeight = 122 self.tableView.rowHeight = UITableViewAutomaticDimension self.tableView.delegate = self self.tableView.dataSource = self savedLoader.startAnimation() //Load first page loadSaved(1) } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return data.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell […]

如何在当前视图控制器中重新加载另一个uiviewcontroller的tableview

请帮我一下 我很抱歉,如果是重复的,但我没有得到要求的答案,这就是为什么我再次问。 我想在第一个视图中重新加载其他视图的表格。 非常感谢。

iOS – 自定义表格单元格不是UITableView的全部宽度

我可能会做这个错误。 所以我创build了一个UITableView,它基本上有一个自动布局的尾部空间设置为主视图。 我正在为这个表格创build一个自定义的单元格,所以我在原型单元格上进行药物定制,并为它创build了我的类。 这一切都工作得很好。 我似乎无法解决的是自定义单元格不是实际表格单元格的全部宽度,所以白色背景只是显示出来。 如果我不使用自定义单元格,则会使用整个宽度表单元格。 我设置单元格内容的约束,以便背景图像应该填充单元格。 我究竟做错了什么? 让我知道你需要什么来帮助解决这个问题。 ProfileCustomCell.h #import <UIKit/UIKit.h> @interface ProfileCustomCell : UITableViewCell { } @property (nonatomic, strong) IBOutlet UILabel *nameLabel; @property (nonatomic, strong) IBOutlet UIImageView *profileImageView; @end ProfileCustomCell.m #import "ProfileCustomCell.h" @implementation ProfileCustomCell – (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.nameLabel.text = nil; } return self; […]

iOS – 另一个线程需要将reloadData发送到mainthread

我有一个单独的线程创build一个UIView对象,将其插入到UITableView的数据源中,然后调用UITableView上的reloadData。 然而,由于它是一个单独的线程,它不能直接调用reloadData,它需要使主线程做到这一点…但你怎么告诉主线程做到这一点? 谢谢

UITableViewCell textLabel颜色不变

我有一个UITableView和cellForRowAtIndexPath方法,我正在改变单元格的一些属性(字体,大小等)现在所有的任务下面列出的工作就好了,除了改变textLabel的颜色。 我不明白为什么只有那个特定的颜色属性不会改变。 我到处都可以想到,为什么它不工作,我卡住了。 有任何想法吗? – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kLocationAttributeCellID = @"bAttributeCellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kLocationAttributeCellID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kLocationAttributeCellID] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleBlue; cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0]; cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; cell.userInteractionEnabled = NO; cell.textLabel.font = [UIFont fontWithName:@"Courier" size:18.0]; […]