Вид таблицы через другую таблицу и пользовательская ячейка таблицы не могут быть показаны - PullRequest
1 голос
/ 08 февраля 2012

От просмотра таблицы к другому представлению таблицы (с использованием Xcode 4.2 и iOS 5).

FirstPage.h

#import "FavoritesController.h"

#import "Profiles.h"

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FavoritesController * favoriteview = [[FavoritesController alloc] init];
    [favoriteview setTitle:@"Favorites"];

    NSMutableArray * profiles = [[NSMutableArray alloc]init ];
    profiles = [NSMutableArray arrayWithCapacity:20];

    Profiles * profile = [[Profiles alloc]init];
    profile.profile_name = @"Woot";
    profile.biz_type_desc = @"Woot 1";
    profile.profile_address = @"123, woot";
    profile.profile_email = @"woot@woot.com";
    [profiles addObject:profile];
    profile=[[Profiles alloc]init];
    profile.profile_name = @"Jin-Aurora";
    profile.biz_type_desc = @"Software";
    profile.profile_address = @"682A";
    profile.profile_email = @"jin@jin.biz";
    [profiles addObject:profile];

    [self.navigationController pushViewController:favoriteview animated:YES];
    favoriteview.profilelist = profiles; 
}

FavoriesController.h

@interface FavoritesController : UITableViewController

@property(nonatomic,strong)NSMutableArray * profilelist;

@end

FavoriteController.m

 #import "FavoritesController.h"
 #import "Profiles.h"
 #import "ProfileCell.h"

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [self.profilelist count];
}

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

    ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Profiles * profile = [self.profilelist objectAtIndex:indexPath.row];

    cell.nameLabel.text = profile.profile_name;
    cell.biztypeLabel.text = profile.biz_type_desc;

    // Configure the cell...

    return cell;
}

Представление таблицы раскадровки

Это ошибка, которую я получил

2012-02-08 22: 28: 37.719 тест [4668: f803] Из-за завершения приложенияк необработанному исключению 'NSInternalInconsistencyException', причина: 'UITableView dataSource должен вернуть ячейку из tableView: cellForRowAtIndexPath:'

Ответы [ 3 ]

2 голосов
/ 08 февраля 2012

Ваш метод cellForRowAtIndexPath пытается удалить из очереди повторно используемую ячейку, но не создает ее, если она не найдена (что произойдет, если для повторного использования нет доступных ячеек)

ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
    cell = [[[ProfileCell alloc] initWithStyle:style reusueIdentifier:CellIdenfitier] autorelease];
1 голос
/ 19 ноября 2012

Обратите внимание, что dequeueReusableCellWithIdentifier: и dequeueReusableCellWithIdentifier: forIndexPath: являются различными методами.

Следующая ссылка может помочь вам.

Ошибка утверждения в dequeueReusableCellWithIxathInde::1007 *

0 голосов
/ 08 февраля 2012

Я не совсем уверен, что вы пытаетесь сделать здесь:

NSMutableArray * profiles = [[NSMutableArray alloc]init ];
profiles = [NSMutableArray arrayWithCapacity:20];

Первая строка создает новый изменяемый массив, называемый профилями. Вторая строка создает автоматически высвобождаемый изменяемый массив с емкостью 20 и назначает его профилям. Таким образом, вы в основном скрываете массив, созданный в первой строке. Вы можете либо сказать

NSMutableArray *profiles = [[NSMutableArray alloc] initWithCapacity:20];

или

NSMutableArray *profiles = [NSMutableArray arrayWithCapacity:20];

Причина, по которой вы рухнули, как упоминалось @ wattson12, заключается в том, что вы удаляете ячейку, которая еще не была создана. Вы всегда хотите попытаться удалить ячейку из очереди, но если она не существует, вам нужно ее создать. Опять же, @ wattson12 предоставил необходимый код для этой задачи.

...