Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode "Use of undeclared identifier"

I know many people ask this but all the answers are specific apps so I don't understand how to work it for my app.

        tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
    }

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

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

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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

        cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
        return cell;` 
    }
like image 482
user1477809 Avatar asked Mar 05 '26 08:03

user1477809


2 Answers

the reason being ut tableData variable is not retained and you have assigned it via factory method with is already autoreleased.

in .h file, make it retain property and use this variable with self. in ur code.

@property(nonatomic,retain) NSArray *tableData;

in .m,

@synthesize tableData;

then use it like:

self.tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto",      nil];

now you wont get any error as tableData is now retained.

do not forget to release it in dealloc if you are not using ARC.

like image 171
Saurabh Passolia Avatar answered Mar 07 '26 22:03

Saurabh Passolia


You have to declare your NSArray as a property and synthetize it. In your class definition:

@property (retain, nonatomic) NSArray *tableData;

And in the implementation:

@synthetize tableData = _tableData;
like image 29
toasted_flakes Avatar answered Mar 07 '26 22:03

toasted_flakes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!