UITableview 有 EXT_BAD_ACCESS 然后向下滚动 [英] UITableview have EXT_BAD_ACCESS then scrolling down

查看:29
本文介绍了UITableview 有 EXT_BAD_ACCESS 然后向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .h 文件中有以下代码

I have following code in .h file

#import <UIKit/UIKit.h>


@interface MessDisViewController : UIViewController {
IBOutlet UITableView * DisTable;
NSMutableArray *massages;
UIActivityIndicatorView * activityIndicator;
CGSize cellSize;
NSXMLParser * friendsParser;
NSMutableDictionary * listOfFriends;
NSString * currentElement;
NSMutableString * currentID, * currentFname;
}
-(void) parseXMLFileAtURL:(NSString *) myUrl;
-(UITableViewCell *) getCellContentView:(NSString *)cellIdentifier;
@end

在 .m 文件中我有

#import "MessDisViewController.h"
#import "MessageDetailView.h"

@implementation MessDisViewController


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}   

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
    cell = [self getCellContentView:CellIdentifier];

UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];

int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

NSString *cellValue = [massages objectAtIndex:indexPath.row];
NSString *title = [[[massages objectAtIndex: storyIndex] objectForKey: @"theme"] stringByReplacingOccurrencesOfString:@"*" withString:@" "];
NSLog(@"%@",title);
lblTemp1.text = title;
lblTemp2.text= [NSString stringWithFormat:@"%@, %@",[[massages objectAtIndex: storyIndex] objectForKey: @"login"],[[massages objectAtIndex: storyIndex] objectForKey: @"activate_date"]];
[cellValue release];
return cell;

}

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

CGRect CellFrame = CGRectMake(0, 0, 300, 60);
CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
CGRect Label2Frame = CGRectMake(10, 33, 290, 25);
UILabel *lblTemp;

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];

//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];

//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont boldSystemFontOfSize:12];
lblTemp.textColor = [UIColor lightGrayColor];
[cell.contentView addSubview:lblTemp];
[lblTemp release];

return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

return 60;
}
- (void) parseXMLFileAtURL:(NSString *) URL{    
massages = [[NSMutableArray alloc] init];

NSURL *xmlURL = [NSURL URLWithString:URL];  
friendsParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[friendsParser setDelegate:self];
[friendsParser setShouldProcessNamespaces:NO];
[friendsParser setShouldReportNamespacePrefixes:NO];
[friendsParser setShouldResolveExternalEntities:NO];
[friendsParser parse];

}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString * errorString = [NSString stringWithFormat:@"Cannot connect to DataBase  (Error code %i )", [parseError code]];
NSLog(@"error parsing XML: %@", errorString);

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            
if ([elementName isEqualToString:@"Message"]){
    listOfFriends = [[NSMutableDictionary alloc] init];
    [listOfFriends setObject:[attributeDict objectForKey:@"theme"] forKey:@"theme"];
    [listOfFriends setObject:[attributeDict objectForKey:@"login"] forKey:@"login"];
    [listOfFriends setObject:[attributeDict objectForKey:@"activate_date"] forKey:@"activate_date"];
    [listOfFriends setObject:[attributeDict objectForKey:@"message_id"] forKey:@"message_id"];
    [massages addObject:[listOfFriends copy]];
}
}   

- (void)viewDidAppear:(BOOL)animated {
 [super viewDidAppear:animated];
NSString *request=[NSString stringWithFormat: @"http://blablabla"];
[self parseXMLFileAtURL:request];

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *mesid = [[NSString alloc] initWithString:[[massages objectAtIndex: storyIndex] objectForKey: @"message_id"]];
NSLog(@"%@",mesid);
MessageDetailView *mesdet = [[MessageDetailView alloc]initWithNibName:nil bundle:nil];
mesdet.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
mesdet.mesid=mesid;
[self presentModalViewController:mesdet animated:YES];

[mesdet release];
mesdet = nil;
}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];

NSLog(@"all done!");
NSLog(@"stories array has %d items", [massages count]);
[DisTable reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}



- (void)dealloc {


[friendsParser release];
[listOfFriends release];    
[super dealloc];
}

@end

当我在模拟器上向下滚动我的 tableview 时,它有 EXT_BAD_ACCESS 为什么会发生以及如何解决这个问题

When I scrolling down my tableview on simulator it have EXT_BAD_ACCESS why it happen and how to solve this problem

推荐答案

启用 NSZombie 并首先测试导致错误的原因

Enable NSZombie and test what is creating the error first

Double-click an executable in the Executables group of your Xcode project.
Click the Arguments tab.
In the "Variables to be set in the environment:" section, make a variable called "NSZombieEnabled" and set its value to "YES". 

祝你好运

这篇关于UITableview 有 EXT_BAD_ACCESS 然后向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆