【发布时间】:2012-02-10 03:44:22
【问题描述】:
我使用了以下代码:
- (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];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.row == 0) {
CGRect myImageRect = CGRectMake(120.0f, 5.0f, 70.0f, 55.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"logo.png"]];
[cell.contentView addSubview:myImage];
}
else {
int arrayIndex = [indexPath row]-1 ;
mdict = [mmenuitems objectAtIndex:arrayIndex];
[mdict retain];
cell.textLabel.text =[mdict objectForKey:@"name"];
我在 mmenuitems 中得到了正确的 JSON 解析消息,并使用 indexPath.row = 0 来显示徽标。
但问题是我没有得到 tableview 中的最后一项。
此外,当我滚动 tableview 时,数据会随机重新加载,并且会重复。
【问题讨论】:
标签: iphone objective-c ios json uitableview