Lee*_*ong 1 iphone uitableview
我一直在尝试各种方法,没有成功改变以下代码......
我有一个nib文件,如果我将所有单元格设置为此工作正常但我只希望其中一个switch语句具有自定义单元格nib文件.有任何想法吗?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSInteger section = [indexPath section];
UITableViewCell *cell;
switch (section)
{
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:@"any-cell"];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
cell.text = [showTimes objectAtIndex:row];
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"any-cell"];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
cell.text = [showTimes objectAtIndex:row];
break;
default:
cell = [tableView dequeueReusableCellWithIdentifier:@"any-cell"];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"any-cell"] autorelease];
cell.text = [showTimes objectAtIndex:row];
break;
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
你需要做两件事:
initWithFrame:reuseIdentifier:您需要从笔尖初始化单元格,而不是UITableViewCell的方法.查看Apple的Table View编程指南中有关使用nib的部分.此外,虽然这在技术上并不是必需的,但UITableViewCell的initWithFrame:reuseIdentifier:方法已被弃用了initWithStyle:reuseIdentifier:.
| 归档时间: |
|
| 查看次数: |
12757 次 |
| 最近记录: |