开发者

iPhone development. EXC_BAD_ACCESS when passing data between views

开发者 https://www.devze.com 2023-02-15 18:40 出处:网络
I have an app which has a simple TableView and pushes to a detailed view when clicking an item. But I am trapped with EXC_BAD_ACCESS when passing a Ringtone* object to detailed view using property.

I have an app which has a simple TableView and pushes to a detailed view when clicking an item. But I am trapped with EXC_BAD_ACCESS when passing a Ringtone* object to detailed view using property.

Here is the definition of ringtone class, which stores the data:

@interface Ringtone : NSObject {
    NSString *ringtoneName;

    NSString *desc;

    NSString *fileName;

    NSDate *date;

    int cId;

    int rId;

    int downloads;

    int fileSize;
}

@property (nonatomic, retain) NSString *ringtoneName;

@property (nonatomic, retain) NSString *desc;

@property (nonatomic, retain) NSString *fileName;

@property (nonatomic, retain) NSDate *date;

@property (nonatomic, assign) int cId;

@property (nonatomic, assign) int rId;

@property (nonatomic, assign) int downloads;

@property (nonatomic, assign) int fileSize;

@end

Here is the property definition in DetailedViewController:

@interface RingtoneDetailViewController : UITableViewController {
    Ringtone *R;
}

@property (nonatomic, retain) Ringtone *R;

@end

Then in the开发者_运维知识库 item selection event:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    RingtoneDetailViewController *detailViewController = [[RingtoneDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];

    Ringtone *r = [ringtoneList objectAtIndex:[indexPath row]];
    detailViewController.R = r; //EXC_BAD_ACCESS This line

    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

}

The EXC_BAD_ACCESS occurred when assigning the R property. Where did I make mistakes?


Pls check if the object of Ringtone is allocated properly.


you Have to synthesize the property in implementation class. Because if you are create a property and if you want to use that property in other class then u must synthesize that property.

0

精彩评论

暂无评论...
验证码 换一张
取 消