Iphone UITableView在滚动后加载相同的标题
我有一个UITableView,它以编程方式显示内容 单元格第一次打开时加载良好,但在滚动之后,它们都显示相同的标题,我认为这是最后一个单元格标题 如果选定单元格,则打开的基础TableView仍然可以正常工作 我查阅了上面的解决方案,但它们要么对我不起作用,要么我太笨了,无法理解问题所在,这似乎是为了节约资源而重用细胞 我将发布CellForRowatineXpath,因为我假设问题存在,如果需要任何进一步的代码,请让我知道Iphone UITableView在滚动后加载相同的标题,iphone,objective-c,xcode,uitableview,Iphone,Objective C,Xcode,Uitableview,我有一个UITableView,它以编程方式显示内容 单元格第一次打开时加载良好,但在滚动之后,它们都显示相同的标题,我认为这是最后一个单元格标题 如果选定单元格,则打开的基础TableView仍然可以正常工作 我查阅了上面的解决方案,但它们要么对我不起作用,要么我太笨了,无法理解问题所在,这似乎是为了节约资源而重用细胞 我将发布CellForRowatineXpath,因为我假设问题存在,如果需要任何进一步的代码,请让我知道 - (UITableViewCell *)tableView:(UI
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *oneLine = [entrys objectAtIndex:position];
NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];
cell.textLabel.text = [lineComponents objectAtIndex:0];
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];
if (position < [entrys count] -2 ) {
position++;
}
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
NSString*oneLine=[entrys objectAtIndex:position];
NSArray*lineComponents=[oneLine Components由字符串分隔:@];“];
cell.textlab.text=[lineComponents objectAtIndex:0];
cell.textlab.textColor=[UIColor colorWithRed:0.0绿色:0.8蓝色:0.2阿尔法:1.0];
如果(位置<[入口计数]-2){
位置++;
}
返回单元;
}
提前感谢试试这张,而不是发帖
NSString *oneLine = [entrys objectAtIndex:indexpath.row];
NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];
cell.textLabel.text = [lineComponents objectAtIndex:0];
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];
或
如果它仍然不工作,那么您的数组没有正确初始化。初始化它试试这个,而不是position
NSString *oneLine = [entrys objectAtIndex:indexpath.row];
NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];
cell.textLabel.text = [lineComponents objectAtIndex:0];
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];
或
如果它仍然不工作,那么您的数组没有正确初始化。初始化它您根本没有使用
indepath
参数。应该是:
NSString *oneLine = [entrys objectAtIndex:indexPath.row];
您根本没有使用
indepath
参数。应该是:
NSString *oneLine = [entrys objectAtIndex:indexPath.row];
问题就在这里
if (position < [entrys count] -2 ) {
position++;
}
if(位置<[entrys count]-2){
位置++;
}
表中的行数大于数组计数entrys
,由于这种情况,您的position
将增加到最后一个对象,此后,该条件将永远不会被调用,因此您的position
指向最后一个对象。
您能告诉我您从表视图:numberofrowsinssection:
方法返回了什么吗?问题就在这里
if (position < [entrys count] -2 ) {
position++;
}
if(位置<[entrys count]-2){
位置++;
}
表中的行数大于数组计数entrys
,由于这种情况,您的position
将增加到最后一个对象,此后,该条件将永远不会被调用,因此您的position
指向最后一个对象。
你能告诉我你从
表格视图:numberofrowsinssection:
方法中返回了什么吗?他拿走了用分号分隔的字符串的第一部分。他拿走了用分号分隔的字符串的第一部分。非常感谢你,我显然被那个不必要的“位置”迷住了-柜台。非常感谢,我显然被那个不必要的“位置”——柜台迷住了。