我需要在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