0
我想創建一個UITableView與子視圖,我用我找到的教程。但是,我無法在桌面上顯示任何數據,沒有錯誤。爲什麼帶子視圖的UITableView不顯示任何數據?
想問一下,如果有人可以看看代碼,並給我一個提示如何讓這個工作?
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(10, 33, 290, 25);
UILabel *lblTemp;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont boldSystemFontOfSize:12];
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
//First get the dictionary object
// NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [[NSArray alloc]initWithObjects: @"One", @"Two", @"Three", nil];
NSString *cellValue = [array objectAtIndex:indexPath.row];
lblTemp1.text = cellValue;
lblTemp2.text = @"Sub Value";
[cellValue release];
return cell;
}
邁克爾,不可思議的我在那裏有錯誤的號碼,當我改變它的作品。謝謝!這是生活作爲n00b我猜:-) – PeterK 2011-03-06 15:28:31
很高興你得到它的工作! – 2011-03-06 15:56:56