Вызов метода делегирования представления UITable - PullRequest
0 голосов
/ 06 декабря 2011

Я работаю с 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];

Я считаю, что эти методы были вызваны, но ничего не произошло(код внутри этих делегатов не работает) .... Я не знаю, почему ???Любые предложения ???

1 Ответ

0 голосов
/ 06 декабря 2011

Напишите код внутри функции нажатия кнопки, он вызовет всех делегатов просмотра таблицы

[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];
}

Попробуйте этобудет работать ..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...