Once an array is properly filled, when I call it again using tableview reload, first time (after clean) returns an empty value and following executions returns EXC_BAD_ACCES. Trying to provide all code needed… Thanks for help!
in .h file:
@interface userViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *appData;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UILabel *status;
IBOutlet UITableView *mainTable;
IBOutlet UIBarButtonItem *refresh;
}
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) UILabel *status;
@property (nonatomic, retain) UITableView *mainTable;
@property (nonatomic, retain) UIBarButtonItem *refresh;
@property (nonatomic, retain) NSArray *appData;
- (IBAction) refresca: (id)sender;
in .m file, when requestFinished function is executed, appData is properly filled.
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"%@", [request responseString]);
[activityIndicator stopAnimating];
activityIndicator.hidden = YES;
appData = [[request responseString] componentsSeparatedByString: @"#"];
int x =0;
while (x<[appData count] - 1)
{
NSLog(@"Data = %@",[appData objectAtIndex: x]);
x = x+1;
}
}
However, after its execution, when reload tableview, appData seems that is empty and previous conted erased!!
2011-10-13 18:10:43.682 Nimbo[444:207] Data = <UITableViewCellContentView: 0x5c93dd0; frame = (0 0; 320 43); layer = <CALayer: 0x5c953b0>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setFrame:CGRectMake(0, 44, 320, 412)];
static NSString* cellIdentifier = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = (UITableViewCell*) [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
int x = 0;
if ([appData count] != 0)
{
NSLog(@"Data = %@",[appData objectAtIndex: 0]);
}
return cell;
}
Looks like your instance variable
appDatais not retained.EDIT: as others have said, using the property is the best way to go. That will retain your new
appDataas well as release objects previously assigned there.Try changing:
to: