将数组插入tableview

时间:2012-07-24 06:43:54

标签: iphone objective-c ios uitableview xcode4.3

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

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

- (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;
}

请帮助谢谢

1 个答案:

答案 0 :(得分:0)

显然你的tableview的delegate / dataSource没有设置。

·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];
}
相关问题