0

我在将数组插入表视图时遇到问题。我有一个数组,我将它存储在alDescArray.

这是alDescArray = ( "Block1", "Block2", "Block3" )通过 NSLog 打印的位置。该表没有显示任何错误时我的代码的哪一部分?

- (void)viewDidLoad
{
    NSArray *BusRoute = alightDesc;
    int i;
    int count = [BusRoute count];
    for (i = 0; i < count; i++)
    {   
        NSDictionary *dic = [BusRoute objectAtIndex: i];
        NSDictionary *STEPS = [dic valueForKey:@"STEPS"];            
        alDescArray = [STEPS valueForKey:@"AlightDesc"];
   }
    [super viewDidLoad];
}

这是tableview的代码

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [alDescArray count];
}

- (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] autorelease];
    }
    cell.textLabel.text = [alDescArray objectAtIndex:indexPath.row];    
    return cell;
}

请帮忙谢谢

4

1 回答 1

0

显然您的 tableview 的委托/数据源未设置。

。H

YourClassName : ParentClass <UITableViewDelegate, UITableViewDataSource>

.m

- (void)viewDidLoad
{
    yourTableView.delegate = self;
    yourTableView.dataSource = self;
    NSArray *BusRoute = alightDesc;
    int i;
    int count = [BusRoute count];
    for (i = 0; i < count; i++)
    {   
        NSDictionary *dic = [BusRoute objectAtIndex: i];
        NSDictionary *STEPS = [dic valueForKey:@"STEPS"];            
        alDescArray = [STEPS valueForKey:@"AlightDesc"];
    }
    [super viewDidLoad];
}
于 2012-07-24T07:04:51.573 回答