我需要在UITableView中顯示我的數組,但我無法正確執行此操作。它不顯示標籤文本,標籤爲空白。這是我迄今爲止所做的。只有圖像顯示在我的UITableView如何填充UITableView?
NSMutableArray *opp;
NSMutableArray *prop;
NSMutableArray *checkA = [NSMutableArray array];
NSArray *values = [dict allValues];
NSArray *keys = [dict allKeys];
NSArray *games = [values valueForKey:@"Game"];
count = [[games objectAtIndex:0]count];
NSUInteger index = 0;
while (index < count) {
Opponent = [[[[[games objectAtIndex:0] valueForKey:@"Opponent"]objectAtIndex:index]valueForKey:@"OpponentName"]valueForKey:@"text"];
[opp addObject:Opponent];
Proponent = [[[[[games objectAtIndex:0] valueForKey:@"Proponent"]objectAtIndex:index]valueForKey:@"ProponentName"]valueForKey:@"text"];
[prop addObject:Proponent];
index++
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
switch(section)
{
case 0: return 2; // section 0 has 2 rows
case 1: return 1; // section 1 has 1 row
default: return 0;
};
}
// Return the row for the corresponding section and row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cells" forIndexPath:indexPath];
UIImageView *images = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 50, 50)];
[images setImage:[UIImage imageNamed:[img objectAtIndex:indexPath.row]]];
[cell addSubview:images];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(131, 27, 59, 21)];
label1.text = [opp objectAtIndex:indexPath.row];
[cell addSubview:label1];
NSLog(@"label 1: ",label1.text);
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(231, 27, 67, 21)];
label2.text = [prop objectAtIndex:indexPath.row];
[cell addSubview:label2];
NSLog(@"label 2: ",label2.text);
return cell;
}
現在它正在工作,忘記初始化我的字符串。現在的問題是它只顯示3行。我期待29行,因爲我的opp有29個對象
通過靜態行值試試這個代碼[cell.contentView addSubview:LABEL1]。你改變你的標籤位置 – iOS
現在它正在工作,但它只顯示3行。我期待29行導致我的opp有29個對象 – drbj