Exec bad access problem
#import "DealList.h"
#import "MyGroupOnDetailedViewController.h"
#import "Deal.h"
#import "DDXML.h"
@implementation DealList
- (void)viewDidLoad {
[super viewDidLoad];
NSString *xmlString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
xmlString = [self textToHtml:xmlString];
NSError *error = nil;
DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlString options:0 error:&error];
NSLog(@"Error:%@",error);
DDXMLElement *FeaturedDeal = [ddDoc rootElement];
Deals = [[NSMutableArray alloc]init];
for (DDXMLElement *n in [FeaturedDeal children]) {
Deal *deal = [[Deal alloc]init];
deal.DealID = [[[n elementsForName:@"DealId"]objectAtIndex:0] stringValue];
deal.Available = [[[n elementsForName:@"Available"]objectAtIndex:0] stringValue];
NSLog(@"%@",deal.Available);
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [Deals count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 120.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
//this works
NSLog(@"%@",[[Deals objectAtIndex:indexPath.row] Available]);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyGroupOnDetailedViewController *myGroupOnDetailedViewController = [[MyGroupOnDetailedViewController alloc] initWithNibName:@"MyGroupOnDetailedViewController" bundle:nil];
myGroupOnDetailedViewController.DealID = [[Deals objectAtIndex:indexPath.row] DealID];
//EXC_BAD_ACCESS:
myGroupOnDetailedViewController.available = [[Deals objectAtIndex:indexPath.row] Available];
}
@end
myGroupOnDetailedViewCont开发者_如何学Pythonroller.available = [[Deals objectAtIndex:indexPath.row] Available];
This line is getting bad access
But while writing the same code in cellForRowAtIndexPath printing the value of Available, DealID can be accessed everywhere.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 1652.
Pending breakpoint 1 - ""Settings.m":50" resolved
Pending breakpoint 2 - ""MyGroupOnDetailedViewController.m":103" resolved
Pending breakpoint 3 - ""DealList.m":184" resolved
Pending breakpoint 4 - ""DealList.m":166" resolved
Pending breakpoint 5 - ""MyGroupOnDetailedViewController.m":75" resolved
Pending breakpoint 6 - ""DealList.m":50" resolved
2011-06-28 14:21:18.139 Feature_list[1652:207] (null)
2011-06-28 14:21:18.151 Feature_list[1652:207] <FeaturedDeal><DealId>167</DealId><Text>$10 for $100 worth Indian fare</Text><ImageUrl>2011/06/large_167.jpg</ImageUrl><Hilights>999999999,88888888,8888888888,8888888888888888,788888,6666666666,555555555</Hilights><Fineprint>77777777777,666666666,555555555,444444444,333333333,2222222222,1111111111</Fineprint><Company>Taiba Foods</Company><ExpiryDate>2011-06-24 22:22:54</ExpiryDate><Value>100</Value><Discount>90</Discount><BuyerCount>1</BuyerCount></FeaturedDeal>
2011-06-28 14:21:18.152 Feature_list[1652:207] Deal ID is: (null)
(gdb) continue
Current language: auto; currently objective-c
2011-06-28 14:21:23.694 Feature_list[1652:207] Error:(null)
2011-06-28 14:21:23.697 Feature_list[1652:207] 1
2011-06-28 14:21:23.697 Feature_list[1652:207] (null)
2011-06-28 14:21:23.698 Feature_list[1652:207] 1
2011-06-28 14:21:23.699 Feature_list[1652:207] (null)
2011-06-28 14:21:23.701 Feature_list[1652:207] deal 3
2011-06-28 14:21:23.703 Feature_list[1652:207] Expiry Date:2011-06-01 08:02:51 +0000
2011-06-28 14:21:23.704 Feature_list[1652:207] test
(gdb) continue
2011-06-28 14:21:24.117 Feature_list[1652:207] 1
2011-06-28 14:21:24.119 Feature_list[1652:207] $10 for $100 worth Indian fare
2011-06-28 14:21:24.120 Feature_list[1652:207] Expiry Date:2011-06-30 16:52:54 +0000
2011-06-28 14:21:24.121 Feature_list[1652:207] test
(gdb) continue
2011-06-28 14:21:25.333 Feature_list[1652:207] 1
2011-06-28 14:21:27.711 Feature_list[1652:207] <Deal: 0x4e86b40>
(gdb) continue
Program received signal: “EXC_BAD_ACCESS”.
(gdb)
With what little information we have, are you sure it's not something silly like
myGroupOnDetailedViewController.available
should be
myGroupOnDetailedViewController.Available
I don't have access to the definition of this object, but you're using uppercase A everywhere else...
Add NSZombieEnabled in your XCode project..
You can find out the error..
http://www.cocoadev.com/index.pl?NSZombieEnabled
精彩评论