调用uitableviewdelegate方法



我正在使用UITableView在UIViewController..我使用以下委托方法.....

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

加载视图后,我发现所有委托都被称为.....但我需要在按钮中调用这些方法点击.....
我试过了....

[self tableView:table numberOfRowsInSection:rows];
[self tableView:table cellForRowAtIndexPath:path];

我发现这些方法被调用了,但是什么都没有发生(这些委托中的代码不起作用)....我不知道为什么?有什么建议吗? ?

在button click函数中编写代码它将调用tableview的所有委托

[self.tableView reloadData];

或解决方案的完整代码为:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    customCell *cell = [[customCell alloc]init];
    if (cell == nil) {
        cell = [[[customCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    // Configure the cell
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil];
    cell = (customCell *)[topLevelObjects objectAtIndex:0];

    int count=0;
    for(id currentObject in topLevelObjects)
    {
        count++;
        if([currentObject isKindOfClass:[customCell class]])
        {
            cell= (customCell *)currentObject;  
            UILabel *sName = (UILabel *)[cell.contentView viewWithTag:1]; 
            //Checking the flag that is set in the btnClicked event
            if (flag) {
                    sName.hidden=YES;
                }
                else{
                sName.text = [arrayResult objectAtIndex:indexPath.row];             
                }
        }
    }
    return cell;
    [topLevelObjects release];
    [cell release]; 
}
-(IBAction) btnClicked:(id) sender{
flag=YES;
[self.tableView reloadData];
}

相关内容

最新更新