-1

maybe somebody can help me. I Have different class objects. They'll get created in the TableView.m file with arrays as properties of these objects. How can I populate the TableView out of these Objects so that every cell contains on object? When I am adding the objects to an array I am getting an error, when I am running the simulator.

Error: App1[6354:7304461] -[Object1 isEqualToString:]: unrecognized selector sent to instance 0x600000455c00

I think that the TableView doensn't know how to create the cell. But I don't have enough experience to know what is really going on.

Thanks

- (void)viewDidLoad {
    [super viewDidLoad];


//creating first Object of NSObject Class Object1
    Object1 *object1Class = [[WLAN alloc]init];

    object1Class.object1PicsCreated = [[NSMutableArray alloc] init];
    object1Class.object1TextsCreated = [[NSMutableArray alloc] init];

    [object1Class.object1PicsCreated addObject:object1Class.picsObject1];
    [object1Class.object1TextsCreated addObject:object1Class.textsObject1];


    //creating second Object of NSObject Class Object2
    Object1 *object1Class = [[WLAN alloc]init];

    object2Class.object2PicsCreated = [[NSMutableArray alloc] init];
    object2Class.object2TextsCreated = [[NSMutableArray alloc] init];

    [object1Class.object2PicsCreated addObject:object2Class.picsObject2];
    [object1Class.object2TextsCreated addObject:object2Class.textsObject2];

if (!_objects){
            _objects = [[NSMutableArray alloc] init];

        }

[_objects addObject:object1Class]
[_objects addObject:object2Class]


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

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

    return _objects.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];



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


    return cell;
}
podoi17
  • 39
  • 9

2 Answers2

0
    static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [NSString stringWithFormat:@"%@",[_objects objectAtIndex:indexPath.row]];
Flyingdodo
  • 21
  • 2
0

Xcode crashes because you pass an instance of Object1 to the setter which expects NSString. UITableView thinks that object is NSString so calls NSString's methods against it (for you it was -isEqualToString:), which is a reason it crashes.

Whatever you want to show needs to be converted to NSString before you pass it there.

How can I populate the TableView out of these Objects so that every cell contains on object?

This is a very strange question. UITableView's rows are UITableViewCell-s. You may not populate a table with anything else.

Maybe, you should describe your tasks in more details.

Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51