Подтвердить что ты не робот

Методы делегатов UITableView

Мне нужен метод делегата UITableView, который нужно вызывать из другой функции во время компиляции... есть ли какие-либо дефолтные методы UITableView, которые я могу использовать? если нет, прокомментируйте, как добавить дополнительный метод делегирования в дополнение к уже существующим.

Заранее спасибо

4b9b3361

Ответ 1

Убедитесь, что вы установили UITableview Delegate в любом случае - от NIB или программно

Использование NIB От Nib: -

enter image description here

Программно: - enter image description here

то: -

-(void)viewWillAppear:(BOOL)animated
{
         tblService.delegate=self;
         tblService.dataSource=self;
         [super viewWillAppear:YES];
}

Используйте следующие делегаты:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;    //count of section
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [catagorry count];    //count number of row from counting array hear cataGorry is An Array
}



- (UITableViewCell *)tableView:(UITableView *)tableView
             cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *MyIdentifier = @"MyIdentifier";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                           reuseIdentifier:MyIdentifier] autorelease];
        }

        // Here we use the provided setImageWithURL: method to load the web image
        // Ensure you use a placeholder image otherwise cells will be initialized with no image
        [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
                       placeholderImage:[UIImage imageNamed:@"placeholder"]];
            cell.textLabel.text = @"My Text";
        return cell;
    }

Below use for set height of cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

        return 80;

}

Below use for gatting particular cells data by selecting row this method called

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        Yourstring=[catagorry objectAtIndex:indexPath.row];      

       //Pushing next view 
        cntrSecondViewController *cntrinnerService = [[cntrSecondViewController alloc] initWithNibName:@"cntrSecondViewController" bundle:nil];
        [self.navigationController pushViewController:cntrinnerService animated:YES];

}

Ответ 2

Я не знаю, существует ли этот метод, но если вам нужны другие методы в делете UITableView, вы можете создать новую категорию UITableViewDelegate.