Можно ли добавить два tableView в UIView? - PullRequest
0 голосов
/ 15 марта 2011

Я использую два UItableView в моих приложениях. Я установил их делегат и источник данных для владельца файла. В части реализации я попробовал:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView=tableView1) 
{
return [tableArr count];
}
if (tableView=tableView2) 
{
    return [tableArr count];
}

}

В методе

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (tableView==tableView1) 
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        }

        cell.textLabel.text=[tableArr objectAtIndex:indexPath.row];
        return cell;

    }
    if (tableView==tableView2) 
    {
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        }

        cell.textLabel.text=[tableArr objectAtIndex:indexPath.row];
        return cell;

    }

и

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

Я также пытался вызвать этот tableView как tableView1 & tableView2. Так можно ли добавить в tableView в UIView?

Ответы [ 3 ]

3 голосов
/ 15 марта 2011

На самом деле вы выполняете присваивание вместо сравнения (= против ==), поэтому он всегда выполняет первое возвращение. Также убедитесь, что tableView1 и tableView2 являются фактически ненулевыми объектами (должны работать соединения IBOutlet или соответствующие методы init).

1 голос
/ 15 марта 2011

Как сказал Eimantas, вы должны попытаться сравнивать, а не присваивать, попробуйте это и убедитесь, что вы проверяете содержимое таблицы также в соответствии с вашими потребностями в cellForRowAtIndexPath:

  if (tableView==tableView1) 
{
return [tableArr count];
}
if (tableView==tableView2) 
{
    return [tableArr count];
}
0 голосов
/ 15 марта 2011

это возможно, но я думаю,

    if (tableView=tableView1) 
{
return [tableArr count];
}
if (tableView=tableView2) 
{
    return [tableArr count];
}

этот код должен быть в

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

а не в

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

и вы также установили ссылочный IBoutlet для соответствующего табличного представления, если добавили его из Интерфейсного разработчика ...?

Использование

[tableView isEqual: tableView1] / * вместо * / if (tableView = tableView1

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