UILabel wrong release into UITableViewCell - iphone

I have a custom UITableViewCel like this:
#synthesize poiNameLabel;
#synthesize poiDistanceLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
CGRect nlabelframe = CGRectMake(NAMELABEL_X, NAMELABEL_Y, NAMELABEL_WIDTH, NAMELABEL_HEIGHT);
UILabel *nlabel = [[UILabel alloc] initWithFrame:nlabelframe];
nlabel.font = [UIFont fontWithName:#"Arial" size:NAMELABEL_FONT];
nlabel.backgroundColor = [UIColor clearColor];
nlabel.minimumFontSize = NAMELABEL_FONT_MIN;
//nlabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:nlabel];
self.poiNameLabel = nlabel;
[nlabel release];
CGRect dlabelframe = CGRectMake(DISTANCELABEL_X, DISTANCELABEL_Y, DISTANCELABEL_WIDTH, DISTANCELABEL_HEIGHT);
UILabel *dlabel = [[UILabel alloc] initWithFrame:dlabelframe];
dlabel.font = [UIFont fontWithName:#"Arial" size:DISTANCELABEL_FONT];
dlabel.backgroundColor = [UIColor clearColor];
dlabel.minimumFontSize = DISTANCELABEL_FONT_MIN;
dlabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:dlabel];
self.poiDistanceLabel = dlabel;
[dlabel release];
self.contentView.backgroundColor = [UIColor clearColor];
self.contentView.opaque = NO;
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)dealloc {
[super dealloc];
[poiNameLabel release];
[poiDistanceLabel release];
}
and this is how I fill it:
NSDictionary *dic = [[NSDictionary alloc] initWithDictionary:[poisSource objectAtIndex:row]];
ResultsViewCell *cell = [[[ResultsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.poiNameLabel.text = [dic objectForKey:#"name"];
float distance = [[dic objectForKey:#"distance"] floatValue];
NSString *distanceWithUnity;
distance = distance*1000;
if (distance > 1000) {
distanceWithUnity = [NSString stringWithFormat:#"%.2f km", distance/1000];
} else {
distanceWithUnity = [NSString stringWithFormat:#"%.0f mt", distance];
}
cell.poiDistanceLabel.text = distanceWithUnity;
[dic release];
return cell;
Everything is ok, but when the UITableCell is deallocated, I get BAD_ACCESS releasing poiDistanceLabel.
I see no problem in my code, no retain errors, so I can't understand what's happening.
The only doubt I have is about how I'm setting the label text: can this be the issue? Why is this happening?

Problem seems to be in your dealloc method:
[super dealloc]
should be the last call in your dealloc method to keep object "alive" while it is deallocating.

Related

Search Bar doesn't work on Device in ios

I created iOS(5.0) application in that I have search Bar, which is used to search the content in server side, while passing keyword entered into search bar the list of content parsed from the xml and shown in Table View,
its working fine in Emulator,.but in device (ipad2 & iphone4s) its not showing table of content were searched.
pls let me know what am making wrong..
Thanks in advance,.
murali.
This is mySearchClass.h
#interface SearchClass : UIViewController<UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource,UIActionSheetDelegate,UISearchBarDelegate, UISearchDisplayDelegate>
{
AppDelegate *abc;
MBProgressHUD *HUD;
IBOutlet UIScrollView *scrv;
IBOutlet UITableView *tableV;
UISearchBar *searchBar;
IBOutlet UILabel *lblTitle;
IBOutlet UIActionSheet *actionSheet;
IBOutlet UIPickerView *pickerView;
IBOutlet UIButton *btnActionSheet;
UIToolbar *pickerToolBar;
NSMutableArray *arrCate;
NSString *key;
}
-(void)cleartable;
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;
#end
//======================
This is my SearchClass.m
#implementation SearchClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.image = [UIImage imageNamed:#"search"];
UIImageView *navImg=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"i-street"]];
self.navigationItem.titleView = navImg;
}
return self;
}
- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg1.png"]];
abc = (AppDelegate*)[[UIApplication sharedApplication]delegate];
//self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//[SearchClass initWithNibName:#"" bundle:nil];
//[SearchClass initWithNibName:#"SearchClass" bundle:nil];
arrCate = [[NSMutableArray alloc]initWithObjects:#"Arts & Entertainment",#"Restaurants",#"Bars, Pubs & Clubs",#"Film and Cinema",#"Live Gigs",#"Shops", nil];
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43 , 320, 480)];
pickerView.delegate = self;
pickerView.dataSource = self;
[pickerView setShowsSelectionIndicator:YES];
pickerToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
pickerToolBar.barStyle = UIBarStyleBlackOpaque;
[pickerToolBar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIButton *btnDone = [UIButton buttonWithType:UIButtonTypeCustom];
[btnDone setFrame:CGRectMake(0, 0, 60, 30)];
[btnDone addTarget:self action:#selector(closeActionSheet) forControlEvents:UIControlEventTouchUpInside];
[btnDone setBackgroundImage:[UIImage imageNamed:#"done.png"] forState:UIControlStateNormal];
UIBarButtonItem *dbtn = [[UIBarButtonItem alloc]initWithCustomView:btnDone];
[barItems addObject:dbtn];
[pickerToolBar setItems:barItems animated:YES];
}
-(IBAction)closeActionSheet
{
lblTitle.text=[arrCate objectAtIndex:[pickerView selectedRowInComponent:0]];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrCate objectAtIndex:row];
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
return [arrCate count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
lblTitle.text = [arrCate objectAtIndex:row];
[abc.arrSearch removeAllObjects];
[tableV reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// NSLog(#"table view count seasrch :%d",[abc.arrSearch count]);
return [abc.arrSearch count];
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
NSString *imgUrl;
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if(indexPath.row > 0)
{
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"line1.png"]];
[cell.contentView addSubview: separator];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *imgbest=[[UIImageView alloc]initWithFrame:CGRectMake(213,4,107,64)];
UIActivityIndicatorView *actSpiner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actSpiner.center = imgbest.center;
[actSpiner startAnimating];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 200, 20)];
lbl.textAlignment = UITextAlignmentLeft;
lbl.font = [UIFont fontWithName:#"Helvetica" size:18.0];
lbl.textColor = [UIColor whiteColor];
lbl.backgroundColor = [UIColor clearColor];
lbl.numberOfLines=0;
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 23, 200, 20)];
lbl1.textAlignment = UITextAlignmentLeft;
lbl1.font = [UIFont fontWithName:#"American Typewriter" size:13.0];
lbl1.textColor = [UIColor whiteColor];
lbl1.backgroundColor = [UIColor clearColor];
lbl1.numberOfLines=0;
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(5,44, 200, 20)];
lbl2.textAlignment = UITextAlignmentLeft;
lbl2.font = [UIFont fontWithName:#"Helvetica-Oblique" size:12.0];
lbl2.textColor = [UIColor whiteColor];
lbl2.backgroundColor = [UIColor clearColor];
lbl2.numberOfLines=0;
if([lblTitle.text isEqualToString:#"Arts & Entertainment"])
{
ArtsClass *arts=[[ArtsClass alloc]init];
arts = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = arts.artThumpImg;
lbl.text=arts.artTitle;
lbl1.text=arts.artDesc;
lbl2.text=arts.artDate;
}
else if([lblTitle.text isEqualToString:#"Restaurants"])
{
ResClass *res=[[ResClass alloc]init];
res = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = res.resLogoImg;
lbl.text=res.resName;
lbl1.text=res.resType;
lbl2.text=res.resPopularDish;
}
else if([lblTitle.text isEqualToString:#"Bars, Pubs & Clubs"])
{
BarClass *bar=[[BarClass alloc]init];
bar = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = bar.barImg;
lbl.text=bar.barTitle;
lbl1.text=bar.barDesc;
lbl2.text=bar.barFacilities;
}
else if([lblTitle.text isEqualToString:#"Film and Cinema"])
{
FilmClass *film=[[FilmClass alloc]init];
film = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = film.filmImg;
lbl.text=film.filmName;
lbl1.text=film.filmSynopsis;
lbl2.text=film.filmReleDate;
}
else if([lblTitle.text isEqualToString:#"Live Gigs"])
{
GigsClass *gigs=[[GigsClass alloc]init];
gigs = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = gigs.eventThumpImg;
lbl.text=gigs.eventTitle;
lbl1.text=gigs.eventCate;
lbl2.text=[NSString stringWithFormat:#"%# - %#",gigs.eventStartDate,gigs.eventEndDate];
}
else if([lblTitle.text isEqualToString:#"Shops"])
{
ShopsClass *shops=[[ShopsClass alloc]init];
shops = [abc.arrSearch objectAtIndex:indexPath.row];
imgUrl = shops.shopThumpImg;
lbl.text=shops.shopName;
lbl1.text=shops.shopDesc;
lbl2.text=shops.shopFacilities;
}
NSURL *url = [NSURL URLWithString:imgUrl] ;
// NSLog(#"image link:%#",url);
dispatch_queue_t currQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_async(currQueue,^{
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
imgbest.image = [UIImage imageWithData:data];
});
});
[cell addSubview:actSpiner];
[cell addSubview:imgbest];
[cell addSubview:lbl];
[cell addSubview:lbl1];
[cell addSubview:lbl2];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([lblTitle.text isEqualToString:#"Arts & Entertainment"])
{
abc.subClassTag=#"ARTS";
abc.classTag = #"GALLERYCLASS";
abc.strTitle = #"Arts & Entertainment";
abc.objArt = [abc.arrArts objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:#"Restaurants"])
{
abc.subClassTag=#"RES";
abc.classTag = #"GALLERYCLASS";
abc.strTitle = #"Restaurants";
abc.objRest = [abc.arrRes objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:#"Bars, Pubs & Clubs"])
{
abc.subClassTag=#"BAR";
abc.classTag = #"GALLERYCLASS";
abc.strTitle = #"Bars, Pubs & Clubs";
abc.objBar = [abc.arrBars objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:#"Film and Cinema"])
{
abc.subClassTag=#"FILMS";
abc.classTag = #"PLAYERCLASS";
abc.strTitle = #"Film and Cinema";
abc.objFilm = [abc.arrFilm objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:#"Live Gigs"])
{
abc.subClassTag=#"GIGS";
abc.classTag = #"GALLERYCLASS";
abc.strTitle = #"Live Gigs";
abc.objGig = [abc.arrGigs objectAtIndex:indexPath.row];
}
else if([lblTitle.text isEqualToString:#"Shops"])
{
abc.subClassTag=#"SHOPS";
abc.classTag = #"GALLERYCLASS";
abc.strTitle = #"Shops";
abc.objShop = [abc.arrShops objectAtIndex:indexPath.row];
}
if([abc.classTag isEqualToString:#"PLAYERCLASS"])
{
PlayerClass *pl = [[PlayerClass alloc]init];
[self.navigationController pushViewController:pl animated:YES];
}
else if([abc.classTag isEqualToString:#"GALLERYCLASS"])
{
GalaryClass *gc = [[GalaryClass alloc]init];
[self.navigationController pushViewController:gc animated:YES];
}
}
- (void)viewDidUnload
{
scrv = nil;
tableV = nil;
searchBar = nil;
lblTitle = nil;
[super viewDidUnload];
}
-(IBAction)getCategory:(id)sender
{
[searchBar resignFirstResponder];
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil //#"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setTag:0];
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view.superview];
[actionSheet addSubview:pickerToolBar];
[actionSheet showInView:self.view.superview];
[actionSheet setBounds:CGRectMake(0, 0, 320, 430)];
}
-(void)cleartable
{
NSArray * ar=[tableV subviews];
for(int j=0;j<ar.count;j++)
{
NSArray *arr=[[ar objectAtIndex:j]subviews];
for(int i=0;i<arr.count;i++)
{
if([[arr objectAtIndex:i]isKindOfClass:[UILabel class]])
{
[[arr objectAtIndex:i]removeFromSuperview];
}
}
}
}
-(void)showProgress
{
//[searchBar resignFirstResponder];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
// Set the hud to display with a color
HUD.color = [UIColor colorWithPatternImage:[UIImage imageNamed:#"box4"]];//[UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];
// HUD.opacity =
HUD.delegate = self;
[HUD showWhileExecuting:#selector(download) onTarget:self withObject:nil animated:YES];
}
-(void)download
{
if([NetworkManager checkForNetworkStatus])
{
ParserClass *p =[[ParserClass alloc]init];
NSLog(#"search bar text %# --- %#",key,lblTitle.text);
if (lblTitle.text==#"Arts & Entertainment")
{
[p search:1 string:key];
}else if(lblTitle.text==#"Restaurants")
{
[p search:5 string:key];
}else if(lblTitle.text==#"Bars, Pubs & Clubs")
{
[p search:4 string:key];
}else if(lblTitle.text==#"Film and Cinema")
{
[p search:2 string:key];
}else if(lblTitle.text==#"Live Gigs")
{
[p search:3 string:key];
}else if(lblTitle.text==#"Shops")
{
[p search:6 string:key];
}
[tableV reloadData];
}
else
{
UIAlertView *alrt = [[UIAlertView alloc]initWithTitle:#"Network Error!" message:#"Please Check your Network connetion.." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alrt show];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
- (void)searchBar:(UISearchBar *)searchBar1 textDidChange:(NSString *)searchText
{
if(![lblTitle.text isEqualToString:#"Select Category"])
{
if(searchBar.text.length > 0)
{
key = searchText;
[self showProgress];
// ParserClass *p =[[ParserClass alloc]init];
// NSLog(#"search bar text %# --- %#",searchText,lblTitle.text);
// if (lblTitle.text==#"Arts & Entertainment")
// {
// [p search:1 string:searchText];
// }else if(lblTitle.text==#"Restaurants")
// {
// [p search:5 string:searchText];
// }else if(lblTitle.text==#"Bars, Pubs & Clubs")
// {
// [p search:4 string:searchText];
// }else if(lblTitle.text==#"Film and Cinema")
// {
// [p search:2 string:searchText];
// }else if(lblTitle.text==#"Live Gigs")
// {
// [p search:3 string:searchText];
// }else if(lblTitle.text==#"Shops")
// {
// [p search:6 string:searchText];
// }
//
// [tableV reloadData];
}
else
{
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:nil message:#"Please Give me some Key words..!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert1 show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:#"Please Select any Category..!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1
{
[searchBar resignFirstResponder];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar1
{
[searchBar resignFirstResponder];
}
#end
Thanks for ur Reply,.
Murali.
wrong string comparison
if (lblTitle.text==#"Arts & Entertainment")
it should be like this - try this it must work & let me know.
if (lblTitle.text isEqualToString:#"Arts & Entertainment")
I am also having some issues in my search class, i am using JSON url.
Where is the Parsing URL, what are the fields in the xml.
Check your parsing url in ur local browser by manual append method using query string ,working or not.
check by trace path, use console log for print the URL.
Check if u are using localhost url in ur program somewhere else.
Check your delegate for search class.
use this link for your reference.
https://iphonedevsdk.com/forum/iphone-sdk-development/50468-xml-table-view-searchbar.html

IPhone - Images making scrolling and other functionality to crash

Everytime i load images in a tableview and try to scroll the table view i get a crash in my simulator but no errors are showing. Could this be that there is to much memory being used.
Below is the code for 1 out the three views:
#import "ResultViewController.h"
#import "JobAddSiteViewController.h"
#import "SpecificAddViewController.h"
#import "JobAddSiteAppDelegate.h"
#import "JSONKit.h"
#implementation ResultViewController
#synthesize listData;
#synthesize listLocation;
#synthesize listPostDate;
#synthesize listLogo;
#synthesize listDescription;
#synthesize uiTableView;
#synthesize buttonPrev;
#synthesize buttonNext;
NSInteger *countPage = 1;
NSMutableArray *tempArray;
NSMutableArray *tempArray2;
NSMutableArray *tempArray3;
NSMutableArray *tempArray4;
NSMutableArray *tempArray5;
-(IBAction)done{
JobAddSiteViewController *second = [[JobAddSiteViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
-(void)loadData{
NSString *strURL2 = [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/totaljobs.php", ""];
NSData *nsData2 = [NSData dataWithContentsOfURL:[NSURL URLWithString: strURL2]];
NSString *dataResult = [[NSString alloc] initWithData:nsData2 encoding:NSUTF8StringEncoding];
tempArray = [[NSMutableArray alloc] init];
tempArray2 = [[NSMutableArray alloc] init];
tempArray3 = [[NSMutableArray alloc] init];
tempArray4 = [[NSMutableArray alloc] init];
tempArray5 = [[NSMutableArray alloc] init];
NSString *strURL = [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/appresults3.php?pg=%d", countPage];
NSData *nsData = [NSData dataWithContentsOfURL:[NSURL URLWithString: strURL]];
NSDictionary *listDictionary = [nsData objectFromJSONData];
NSArray* people =[listDictionary objectForKey:#"jobs"];
for (NSDictionary *person in people) {
NSString *str = [NSString stringWithFormat:#"%#", [person valueForKey:#"position"]];
NSString *str2 = [NSString stringWithFormat:#"%#", [person valueForKey:#"subcounty"]];
NSString *str3 = [NSString stringWithFormat:#"%#", [person valueForKey:#"postdate"]];
NSString *str4 = [NSString stringWithFormat:#"%#", [person valueForKey:#"logo"]];
NSString *str5 = [NSString stringWithFormat:#"%#", [person valueForKey:#"description"]];
if(![str isEqualToString:#"<null>"])
{
NSString *position = [person objectForKey:#"position"];
[tempArray addObject: position];
if(![str2 isEqualToString:#"<null>"])
{
NSString *subcounty = [person objectForKey:#"subcounty"];
[tempArray2 addObject: subcounty];
}
else{
[tempArray2 addObject: #"-"];
}
if(![str3 isEqualToString:#"<null>"])
{
NSString *postDate = [person objectForKey:#"postdate"];
[tempArray3 addObject: postDate];
}
else{
[tempArray3 addObject: #"-"];
}
if(![str4 isEqualToString:#"<null>"])
{
NSString *logo = [person objectForKey:#"logo"];
[tempArray4 addObject: [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/employers/logo/Files/%#", logo]];
}
else{
[tempArray4 addObject: [NSString stringWithFormat:#"http://www.bestitjobs.co.uk/employers/logo/Files/%#", "noimage.gif"]];
}
if(![str5 isEqualToString:#"<null>"])
{
NSString *description = [person objectForKey:#"description"];
[tempArray5 addObject: description];
}
else{
[tempArray5 addObject: #"-"];
}
}
}
if (countPage == 1) {
[self.buttonPrev setEnabled:FALSE];
}
else {
[self.buttonPrev setEnabled:TRUE];
}
NSInteger val = [dataResult intValue];
NSInteger pageEnd = val/10;
if (countPage < pageEnd) {
[self.buttonNext setEnabled:TRUE];
}
else {
[self.buttonNext setEnabled:FALSE];
}
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"iPhone", #"iPod",#"iPad",nil];
self.listData = tempArray;
self.listLocation = tempArray2;
self.listPostDate = tempArray3;
self.listLogo = tempArray4;
self.listDescription = tempArray5;
[self.listData release];
[self.listLocation release];
[self.listPostDate release];
[self.listLogo release];
[self.listDescription release];
tempArray = nil;
tempArray2 = nil;
tempArray3 = nil;
tempArray4 = nil;
tempArray5 = nil;
}
- (void)viewDidLoad {
[self loadData];
[super viewDidLoad];
}
- (void)dealloc {
[tempArray dealloc];
[tempArray2 dealloc];
[tempArray3 dealloc];
[tempArray4 dealloc];
[tempArray5 dealloc];
[self.listData dealloc];
[self.listLocation dealloc];
[self.listPostDate dealloc];
[self.listLogo dealloc];
[self.listDescription dealloc];
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (IBAction)prev{
countPage = countPage - 1;
[self.listData removeAllObjects];
[self.listLocation removeAllObjects];
[self.listPostDate removeAllObjects];
[self.listLogo removeAllObjects];
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"1", #"2",#"3",nil];
//self.listData = array;
[self loadData];
[self.uiTableView reloadData];
}
- (IBAction)next{
countPage = countPage + 1;
[self.listData removeAllObjects];
[self.listLocation removeAllObjects];
[self.listPostDate removeAllObjects];
[self.listLogo removeAllObjects];
//NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"1", #"2",#"3",nil];
//self.listData = array;
[self loadData];
[self.uiTableView reloadData];
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
JobAddSiteAppDelegate *ja = (JobAddSiteAppDelegate *)[[UIApplication sharedApplication] delegate];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UILabel class]]){
UILabel *label = (UILabel *)view;
if (label.tag == 1) {
ja.jobText = label.text;
}
if (label.tag == 2) {
ja.locationText = label.text;
}
if (label.tag == 3) {
ja.dateText = label.text;
}
if (label.tag == 4) {
}
if (label.tag == 5) {
ja.specificText = label.text;
}
}
if ([view isKindOfClass:[UIImageView class]]){
UIImageView *image = (UIImageView *)view;
if (image.tag = 4){
ja.logoText = image.image;
}
}
}
SpecificAddViewController *second = [[SpecificAddViewController alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (indexPath.section == 1 && indexPath.row == 1) {
return 65;
}
return 65;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
UILabel *labelMain;
UILabel *labelLocation;
UILabel *labelDate;
UIImageView *image;
UILabel *ref;
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
image = [[[UIImageView alloc] initWithFrame:CGRectMake(0,3,80,62)] autorelease];
image.tag = 4;
[cell.contentView addSubview:image];
labelMain = [[[UILabel alloc] initWithFrame:CGRectMake(90,3,200,20)] autorelease];
labelMain.tag = 1;
labelMain.font = [UIFont systemFontOfSize:14.0];
[cell.contentView addSubview:labelMain];
labelLocation = [[[UILabel alloc] initWithFrame:CGRectMake(90,20,200,20)] autorelease];
labelLocation.tag = 2;
labelLocation.font = [UIFont systemFontOfSize:12.0];
labelLocation.textColor = [UIColor darkGrayColor];
[cell.contentView addSubview:labelLocation];
labelDate = [[[UILabel alloc] initWithFrame:CGRectMake(90,40,200,20)] autorelease];
labelDate.tag = 3;
labelDate.font = [UIFont systemFontOfSize:12.0];
labelDate.textColor = [UIColor darkGrayColor];
[cell.contentView addSubview:labelDate];
ref = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] autorelease];
ref.tag = 5;
[cell.contentView addSubview:ref];
}
[(UILabel *)[cell.contentView viewWithTag:1] setText:[self.listData objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:2] setText:[self.listLocation objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:3] setText:[self.listPostDate objectAtIndex:indexPath.row]];
[(UILabel *)[cell.contentView viewWithTag:5] setText:[self.listDescription objectAtIndex:indexPath.row]];
NSString *imagePath = [self.listLogo objectAtIndex:indexPath.row];
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]]];
return cell;
}
#end
The call
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagePath]]];
will block the execution thread and being indeterminately long in terms of network use this is a bad thing. Each of your cells needs to wait to the image to load.
Check out "lazy loading of tableView cells" as a research topic.
Instead you should give the URL to the cell and tell it to load the image off the main thread.
as in
[cell loadImageAtURL:someURL];
and within a UITableViewCell subclass implementation
-(void)loadImageAtURL:(NSURL *)aurl
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:aurl];
if (data) {
UIImage *image = [UIImage imageWithData:data];
//must update UI on main queue
dispatch_async(dispatch_get_main_queue() ,^{
self.cellImageView = image;
}
}
});
}
Theres also a ton of Obj-C image loaders . EGOCache is my go to library but have a look round.
In summary the cell needs to own the image load process not the tableview because theres no guarantee that the cell will not be reused before the image loads and displays.
NSInteger is a primitive type, which means it can be stored locally on the stack. You don't need to use a pointer to access it. The way you are using it i think is a problem, getting the pointer value instead of the actual value of the primitive type.
I think this is what you want for the declaration/initialization of countPage:
NSInteger countPage = 1;

How can I search data from tableview cell?

I have an UITableview controller which representing fetched XML data. For representing these data I used five UILabel. Now I have to add a searchbar at the top of the UITableview. So programmatically I have added a searchbar.
Now I have used searching theorem for search data from the UITableview. But It is not working. I can search data from UItableview when only one text in the UItableviewcell without any UIlabel or something else but in my UItableviewcell cell are taking five UILabel that's why it's becoming tough for me to search data from the UItableviewcell. For understanding I am attaching my code how I am representing my XML data in tableview cell.
This is my XML data representation in UITableviewCell...
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:15.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"arrow.png"]];
cell.accessoryView = imageView;
cell.accessoryType = UITableViewCellSelectionStyleNone;
tableView.separatorColor = [UIColor clearColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
cellView = [[[UIView alloc] initWithFrame:CGRectMake(5,8,290, 120)] autorelease];
cellView.backgroundColor = [UIColor clearColor];
cellView.tag =10;
[cell.contentView addSubview:cellView];
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 40, 48, 48)];
imgView.image = [UIImage imageNamed:#"productbox.png"];
imgView.layer.borderColor = [UIColor blackColor].CGColor;
imgView.layer.borderWidth = 2.0;
imgView.tag = 5;
[cellView addSubview:imgView];
CGRect idLabelRect = CGRectMake(65, 0, 190, 18);
idLabel = [[[UILabel alloc] initWithFrame:idLabelRect] autorelease];
idLabel.textAlignment = UITextAlignmentLeft;
idLabel.textColor = [UIColor blackColor];
idLabel.font = [UIFont systemFontOfSize:12];
idLabel.backgroundColor = [UIColor clearColor];
idLabel.layer.borderColor = [UIColor grayColor].CGColor;
idLabel.tag = 0;
CGRect statusRect = CGRectMake(65, 22, 190, 22);
statusLabel = [[[UILabel alloc] initWithFrame:statusRect] autorelease];
statusLabel.textAlignment = UITextAlignmentLeft;
statusLabel.textColor = [UIColor blackColor];
statusLabel.font = [UIFont systemFontOfSize:12];
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.layer.borderColor = [UIColor grayColor].CGColor;
statusLabel.tag = 1;
CGRect orderDateRect = CGRectMake(65, 48, 190, 22);
orderDate = [[[UILabel alloc] initWithFrame:orderDateRect] autorelease];
orderDate.textAlignment = UITextAlignmentLeft;
orderDate.textColor = [UIColor blackColor];
orderDate.font = [UIFont systemFontOfSize:12];
orderDate.backgroundColor = [UIColor clearColor];
orderDate.layer.borderColor = [UIColor grayColor].CGColor;
orderDate.tag = 2;
CGRect byRect = CGRectMake(65, 75, 190, 22);
byLabel = [[[UILabel alloc] initWithFrame:byRect] autorelease];
byLabel.textAlignment = UITextAlignmentLeft;
byLabel.textColor = [UIColor blackColor];
byLabel.font = [UIFont systemFontOfSize:12];
byLabel.backgroundColor = [UIColor clearColor];
byLabel.layer.borderColor = [UIColor grayColor].CGColor;
byLabel.tag = 3;
CGRect totalRect = CGRectMake(65, 98, 190, 22);
totalLabel = [[[UILabel alloc] initWithFrame:totalRect] autorelease];
totalLabel.textAlignment = UITextAlignmentLeft;
totalLabel.textColor = [UIColor blackColor];
totalLabel.font = [UIFont systemFontOfSize:12];
totalLabel.backgroundColor = [UIColor clearColor];
totalLabel.layer.borderColor = [UIColor grayColor].CGColor;
totalLabel.tag = 4;
[cellView addSubview:idLabel];
[cellView addSubview:statusLabel];
[cellView addSubview:orderDate];
[cellView addSubview:byLabel];
[cellView addSubview:totalLabel];
}
if(searching == YES){
//[cell setText:[tableData objectAtIndex:indexPath.row]];
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
}
else{
cellView = (UIView *)[cell.contentView viewWithTag:10];
idLabel = (UILabel *)[cellView viewWithTag:0];
statusLabel = (UILabel *)[cellView viewWithTag:1];
orderDate = (UILabel *)[cellView viewWithTag:2];
byLabel = (UILabel *)[cellView viewWithTag:3];
totalLabel = (UILabel *)[cellView viewWithTag:4];
imgView = (UIImageView *)[cellView viewWithTag:5];
if(pendingOrder == NO && todaysOrder == NO){
idLabel.text = [NSString stringWithFormat:#"Order Id: %#",[[records objectAtIndex:indexPath.section] objectAtIndex:0]];
statusLabel.text = [NSString stringWithFormat:#"Status: %#",[[records objectAtIndex:indexPath.section] objectAtIndex:1]];
orderDate.text = [NSString stringWithFormat:#"Date: %#",[[records objectAtIndex:indexPath.section] objectAtIndex:2]];
byLabel.text =[NSString stringWithFormat:#"By: %#",[[records objectAtIndex:indexPath.section] objectAtIndex:3]];
totalLabel.text =[NSString stringWithFormat:#"Total: %#",[[records objectAtIndex:indexPath.section] objectAtIndex:4]];
}
else if(pendingOrder == YES && todaysOrder == NO){
idLabel.text = [NSString stringWithFormat:#"Order Id: %#",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:0]];
statusLabel.text = [NSString stringWithFormat:#"Status: %#",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:1]];
orderDate.text = [NSString stringWithFormat:#"Date: %#",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:2]];
byLabel.text =[NSString stringWithFormat:#"By: %#",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:3]];
totalLabel.text =[NSString stringWithFormat:#"Total: %#",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:4]];
}
}
return cell;
}
And this searching Delegate.....
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
searching = YES;
// only show the status bar’s cancel button while in edit mode
sBar.showsCancelButton = YES;
sBar.autocorrectionType = UITextAutocorrectionTypeNo;
// flush the previous search content
[tableData removeAllObjects];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
searching = NO;
sBar.showsCancelButton = NO;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[tableData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:#""] && searchText==nil){
[tableview reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText];
if(r.location != NSNotFound)
{
if(r.location== 0)//that is we are checking only the start of the names.
{
[tableData addObject:name];
}
}
counter++;
[pool release];
}
[tableview reloadData];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
// if a valid search was entered but the user wanted to cancel, bring back the main list content
[tableData removeAllObjects];
searching = NO;
[tableData addObjectsFromArray:dataSource];
#try{
searching = NO;
[tableview reloadData];
}
#catch(NSException *e){
}
[sBar resignFirstResponder];
sBar.text = #"";
}
// called when Search (in our case “Done”) button pressed
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[sBar resignFirstResponder];
}
For more help to understand i am also attaching my viewDidLoad....
//Add the search bar
sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,50)];
sBar.delegate = self;
searching = NO;
[self.view addSubview:sBar];
tableview.dataSource = self;
tableview.delegate = self;
//initialize the two arrays; datasource will be initialized and populated by appDelegate
searchData = [[NSMutableArray alloc] init];
tableData = [[NSMutableArray alloc] init];
[tableData addObjectsFromArray:dataSource];//on launch it should display all the records
Edit
This is my edited portion of numberOfSectionsInTableView and numberOfRowsInSection...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(searching == YES){
searching = NO;
sectionCount = [tableData count];
}
else {
if(pendingOrder == NO && todaysOrder == NO){
sectionCount = [records count];
NSLog(#"section cout: %d",sectionCount);
}
else if(pendingOrder == YES && todaysOrder == NO){
//Total pending order counting
sectionCount = [pendingRecords count];
NSLog(#"section cout for pending: %d",sectionCount);
}
else if(pendingOrder == NO && todaysOrder == YES){
NSLog(#"todays order number counting");
}
}
return sectionCount;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
Try this:-
copylistofItem is NSMutableArray copying data that matched with search bar criteria.
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
int i=0
for (NSString *str in [records objectAtIndex:indexPath.i] objectAtIndex:0])
{
[searchArray addObject:str];
i++;
}
for (NSString *sTemp in searchArray)
{
NSString *txtToSearch =[[NSString alloc] initWithString:[sTemp substringWithRange:NSMakeRange(0,[searchText length])]];
if([[txtToSearch lowercaseString] isEqualToString:[searchText lowercaseString]])
{
[copyListOfItems addObject:sTemp];
}
}
[searchArray release];
searchArray = nil;
}
Also we want to know what you have written in your numberOfSections tableView Delegate.

Crash after returning to tableview

So I am writing an app to read an rss feed, and display the contents in a tableview. It also lets the user play back mp3s that it finds for each item. Anyway the app seemed to be running fine before I started adding new views. Now every time I come back from a view and scroll around a bit, I get "Program received signal "SIGABRT"" or something similar.
here's most of the program:
- (IBAction)playAction:(id)sender
{
// Get row
UIButton *senderButton = (UIButton *)sender;
UITableViewCell *buttonCell =
(UITableViewCell *) [[senderButton superview] superview];
NSInteger buttonRow = [[self.tableView
indexPathForCell:buttonCell] row];
// Entry for row
RSSEntry *senderEntry = [_allEntries objectAtIndex:buttonRow];
// This is where _allEntries gets filled
- (void)requestFinished:(ASIHTTPRequest *)request {
[_queue addOperationWithBlock:^{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil)
{
NSLog(#"Failed to parse %#", request.url);
}
else
{
NSMutableArray *entries = [NSMutableArray array];
[self parseRss:doc.rootElement entries:entries];
if ([_allEntries count] > 0) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// Update
int i=0;
while (![[[_allEntries objectAtIndex:i] articleUrl] isEqualToString:[[entries objectAtIndex:i] articleUrl]])
{
[_allEntries insertObject:[entries objectAtIndex:i] atIndex:0];
i++;
}
[self.tableView reloadData];
}];
}
else
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (RSSEntry *entry in entries)
{
[_allEntries addObject:entry];
}
NSLog(#"entries:%d", [_allEntries count]);
[self.tableView reloadData];
}];
}
}
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"View did load");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:#selector(refreshButton:)];
pauseImage = [UIImage imageNamed:#"pause_circle_small.png"];
playImage = [UIImage imageNamed:#"play_circle_small.png"];
player = nil;
isPlaying = NO;
self.title = #"Feed";
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feed = [[NSString alloc] initWithString:#"http://site.org/rss/"];
[self refresh];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_allEntries count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UILabel *mainLabel, *secondLabel;
UIButton *playBtn;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(42.0, 5.0, 250.0, 20.0)] autorelease];
mainLabel.tag = MAINLABEL_TAG;
mainLabel.font = [UIFont fontWithName:#"Arial-BoldMT" size:18.0];
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview:mainLabel];
secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(42.0, 27.0, 250.0, 15.0)] autorelease];
secondLabel.tag = SECONDLABEL_TAG;
secondLabel.font = [UIFont fontWithName:#"ArialMT" size:14.0];
secondLabel.textAlignment = UITextAlignmentLeft;
secondLabel.textColor = [UIColor colorWithRed:222.0/255.0 green:95.0/255.0
blue:199.0/255.0 alpha:1.0];
secondLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview:secondLabel];
playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
playBtn.tag = PLAYBTN_TAG;
playBtn.frame = CGRectMake(2.0, 6.0, playImage.size.width, playImage.size.height);
[playBtn setBackgroundImage:playImage forState:UIControlStateNormal];
//[playBtn setBackgroundImage:playImage forState:UIControlStateHighlighted];
[playBtn addTarget:self action:#selector(playTapped:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:playBtn];
}
else
{
mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
playBtn = (UIButton *)[cell.contentView viewWithTag:PLAYBTN_TAG];
}
// Alternate bg color
if (indexPath.row%2 == 0) {
UIColor *altColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0
blue:230.0/255.0 alpha:1];
mainLabel.backgroundColor = altColor;
secondLabel.backgroundColor = altColor;
}
else
{
UIColor *altColor = [UIColor colorWithRed:255.0 green:255.0
blue:255.0 alpha:1];
mainLabel.backgroundColor = altColor;
secondLabel.backgroundColor = altColor;
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSLog(#"Entry: %#", entry);
// Manage play button
if (entry == currEntry)
{
if(isPlaying)
{
[playBtn setBackgroundImage:pauseImage forState:UIControlStateNormal];
}
else
{
[playBtn setBackgroundImage:playImage forState:UIControlStateNormal];
}
}
else
[playBtn setBackgroundImage:playImage forState:UIControlStateNormal];
mainLabel.text = entry.articleTitle;
secondLabel.text = entry.articleArtist;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
DetailView *detailViewController = [[DetailView alloc] initWithNibName:#"DetailedView" bundle:[NSBundle mainBundle]];
RSSEntry *entry = [_allEntries objectAtIndex:[indexPath row]];
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.songTitle.text = entry.articleTitle;
detailViewController.artistName.text = entry.articleArtist;
[entry release];
[detailViewController release];
}
- (void)dealloc
{
[player release];
player = nil;
[_queue release];
_queue = nil;
[_feed release];
_feed = nil;
[_allEntries release];
_allEntries = nil;
[super dealloc];
}
#end
Please Dont release any #synthesize variable. You should only release it in dealloc method
It's a wild guess, but you don't retain the images that you get in viewDidLoad:
pauseImage = [UIImage imageNamed:#"pause_circle_small.png"];
playImage = [UIImage imageNamed:#"play_circle_small.png"];
Either use retaining property and dot syntax or send each a retain.
AHAA!!! I was setting my RSSEntry to autorelease before putting them in the _allEntries array. They were getting dealloc'd when I changed views. Don't do that. Thanks for the help everyone. That was so simple, I feel dumb now.
please don't release the self.feed and also when unload or dealloc the view at that time put delegate nil means
tableview.delegate = nil;
this one is the main thing check after this i think u don't nil the delegate of tableview.
without line where you get crash its hard to tell, but most likely you accessing some object what was dealloc'ed
most likely its here
self.feed = [[NSString alloc] initWithString:#"http://site.org/rss/music"];
[self.feed release];
you releasing objects right away, but its hard to tell without knowing if you have retained property

Simple Question UITableView

Hey everbody. Im getting trouble with a simple thing. But i'm missing some detail. I'm trying to set up the styles of the TableView. I've edited the table on visual, but seems do not take effect what i do.
What im doing wrong?
#implementation ComentariosViewController
#synthesize listaComentarios, tabelaComentarios;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [listaComentarios count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
//cell.font = [UIFont boldSystemFontOfSize:13];
}
NSString *cellValue = [listaComentarios objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
- (void)viewDidLoad
{
tabelaComentarios = [[UITableView alloc] initWithFrame:CGRectZero];
tabelaComentarios.delegate = self;
tabelaComentarios.dataSource = self;
//bkg.image = [UIImage imageNamed:#"BkgComentarios.png"];
tabelaComentarios.autoresizesSubviews = YES;
//
// Change the properties of the imageView and tableView (these could be set
// in interface builder instead).
//
tabelaComentarios.separatorStyle = UITableViewCellSeparatorStyleNone;
tabelaComentarios.rowHeight = 100;
tabelaComentarios.backgroundColor = [UIColor clearColor];
//imageView.image = [UIImage imageNamed:#"gradientBackground.png"];
//
// Create a header view. Wrap it in a container to allow us to position
// it better.
//
UIView *containerView =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 60)]
autorelease];
UILabel *headerLabel =
[[[UILabel alloc]
initWithFrame:CGRectMake(10, 20, 300, 40)]
autorelease];
headerLabel.text = NSLocalizedString(#"Comentários", #"");
headerLabel.textColor = [UIColor grayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[containerView addSubview:headerLabel];
self.tabelaComentarios.tableHeaderView = containerView;
self.view = tabelaComentarios;
}
-(void)loadView{
// XML
listaComentarios = [[NSMutableArray alloc] init];
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:#"http://localhost/dev/mcomm/produto.xml"]] retain];
TBXMLElement * rootXMLElement = tbxml.rootXMLElement;
TBXMLElement * comentarios = [TBXML childElementNamed:#"comentarios" parentElement:rootXMLElement];
TBXMLElement * comentario = [TBXML childElementNamed:#"comentario" parentElement:comentarios];
while (comentario) {
NSString * descText = [TBXML textForElement:comentario];
NSLog(#"%#", descText);
[listaComentarios addObject:descText];
comentario = [TBXML nextSiblingNamed:#"comentario" searchFromElement:comentario];
}
[tbxml release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[listaComentarios release];
[tabelaComentarios release];
[super dealloc];
}
#end
If you're using Interface builder to add the table, try commenting out this line:
tabelaComentarios = [[UITableView alloc] initWithFrame:CGRectZero];