strange Memory leaks - iphone

My iPad Application facing few memory leaks. here is screen shot and code.I am rloading table data after each second to show progress.so how can i get this fix.
this always happen when i reload table
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* Identifier = #"OrderCustomCell";
UserCustomCell* cells =(UserCustomCell*) [tableView dequeueReusableCellWithIdentifier:Identifier];
if (cells == nil)
{
NSArray* topLevelObjects=[[NSBundle mainBundle] loadNibNamed:#"UserCustomCell" owner:self options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cells=(UserCustomCell *)currentObject;
break;
}
}
}
NSDictionary* dic = [tableDataArray objectAtIndex:indexPath.row];
cells.selectionStyle = UITableViewCellEditingStyleNone;
cells.brandName.text = [dic objectForKey:#"brandname"];
[cells.msyncBtn setTag:indexPath.row];
NSString* status = [dic objectForKey:#"status"];
if ([status isEqualToString:#""])
{
cells.status.text = [NSString stringWithFormat:#"0%# Completo",#"%"];
}
else
{
cells.status.text = [NSString stringWithFormat:#"%#%# Completo",status,#"%"];
}
NSString* syncDate = [dic objectForKey:#"syncDate"];
if ([syncDate isEqualToString:#""])
{
cells.syncDate.text = [NSString stringWithFormat:#"Não sincronizado"];
}
else
{
cells.syncDate.text = [NSString stringWithFormat:#"%#",syncDate];
}
NSString* totalloaded = [dic objectForKey:#"totalloaded"];
if ([totalloaded isEqualToString:#""])
{
cells.totalLoaded.text = [NSString stringWithFormat:#""];
}
else
{
cells.totalLoaded.text = [NSString stringWithFormat:#"%#",totalloaded];
}
return cells;
}
Please check this image

Try this
if (cells == nil)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSArray* topLevelObjects=[[NSBundle mainBundle] loadNibNamed:#"UserCustomCell" owner:self options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cells=(UserCustomCell *)currentObject;
break;
}
}
[pool drain];
}

Related

MKMapView on UITablViewCell crashes

I want to display MKMapView in a last cell of UITableView.
I have a MKMapView in a UITableViewCell When I scroll the UITableViewCell it refreshes MKMapView. and it crashes with ERROR: MKMapView must be initialized on the main thread.
What should I do to prevent the MKMapView from reloading when I scroll my scrollview of UITableView ?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.view endEditing:YES];
if (indexPath.row !=[arrExit count]) //If it is not last cell
{
static NSString *CellIdentifier = #"BTSTicketsCellIdentifier";
BTSComparePricesCell *cell = (BTSComparePricesCell *)[tblComparePrices dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"BTSComparePricesCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[BTSComparePricesCell class]])
cell = (BTSComparePricesCell *)oneObject;
}
if (!isDragging_msg && !isDecliring_msg)
{
[dicImages_msg setObject:[UIImage imageNamed:#"rowDefault.png"] forKey:[[arrExit objectAtIndex:indexPath.row] valueForKey:#"Merchant_Logo"]];
[self performSelectorInBackground:#selector(downloadImage_3:) withObject:indexPath];
}
return cell;
}
else{ //If it is a last cell
static NSString *CellIdentifier = #"BTSTicketsCell";
BTSMapViewCell *cell = (BTSMapViewCell *)[tblComparePrices dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"BTSMapViewCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[BTSMapViewCell class]])
cell = (BTSMapViewCell *)oneObject;
}
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:[flux objectForKey:#"Venue"]
completionHandler:^(NSArray* placemarks, NSError* error)
{
if (placemarks && placemarks.count > 0)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
[cell.MapVw addAnnotation:placemark];
CLLocationCoordinate2D _venue = placemark.coordinate;
[cell.MapVw setCenterCoordinate:_venue];
MKCoordinateRegion region = cell.MapVw.region;
region.span.longitudeDelta = 1.0;
region.span.latitudeDelta = 1.0;
[cell.MapVw setRegion:region animated:YES];
}
}
];
return cell;
}
}
Thanks in advance.
Try this, hope it will work
Create a MKMapView Instance with strong reference in your View Controller where you are loading the map in table view. Assign the lat long values to that map view instance. On CellforRowAtIndexpath set the cell.MapVw = mapViewInstance .

using of two different type of custom cell in same table view?

thanks in advance.
in my app, i have a tableview, in which i have to use two different style of custom cell, i made two custom cell, and in tableView cellForRowAtIndexPath method i used two identifier for cell, even i tried for two section. but its not working. it is giving me "EXE BAD Excess" or some time other kind of error. below is my code.
Error : thread1_EXE_BAD_Access(code = 2 ,address 0 x 0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
//CatIdentifier
static NSString *CellIdentiFier = #"CatIdentifier";
static NSString *Cell1IdentiFier = #"CatIdentifier1";
if (indexPath.section == 0)
{
CommitteCell *cell = ( CommitteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentiFier];
if(cell == nil)
{
cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:#"CommitteeCell" owner:self options:nil] objectAtIndex:0];
}
if (indicator == 1)
{
cell.lblName.text = str;
}
else
{
cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];
}
cell.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell.backgroundView).image = img;
return cell;
}
else
{
Committee2Cell *cell1 = (Committee2Cell *)[tableView dequeueReusableCellWithIdentifier:Cell1IdentiFier];
if(cell1 == nil)
{
cell1 = (Committee2Cell *)[[[NSBundle mainBundle] loadNibNamed:#"Committee2Cell" owner:self options:nil] objectAtIndex:0];
}
cell1.lblPost1.text = strPost;
cell1.txtName.text = strName;
cell1.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell1.backgroundView).image = img;
return cell1;
}
}
section in tableview and rows in section method are as below.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 0:
return [arrayName count]-1;
break;
case 1:
return 1;
break;
default:
break;
}
return 0;
}
please if anyone can fine that where is my mistake . thanks again.
data of array and label is as below.
-(void)NewsParser:(NSMutableDictionary *)dic
{
NSLog(#"dic = %#",dic);
arrayName = [[NSMutableArray alloc]init];
arrayPost = [[NSMutableArray alloc]init];
arrayimage= [[NSMutableArray alloc]init];
strPost = [[NSString alloc]init];
strName = [[NSString alloc]init];
strPost = [[dic valueForKey:#"post"]objectAtIndex:8];
strName = [[dic valueForKey:#"name"]objectAtIndex:8];
NSLog(#"Name = %#",strName);
NSLog(#"Post = %#",strPost);
for(int i=0;i<[dic count]-1;i++)
{
[arrayName addObject:[[dic valueForKey:#"name"]objectAtIndex:i]];
[arrayPost addObject:[[dic valueForKey:#"post"]objectAtIndex:i]];
[arrayimage addObject:[[dic valueForKey:#"pic"]objectAtIndex:i]];
}
NSLog(#"array = %#",arrayName);
NSLog(#"array = %#",arrayPost);
NSLog(#"array = %#",arrayimage);
[table1 reloadData];
}
I think a cleaner approach would be to use a container view with two different kind of cells and then selectively show/hide the view relevant for that cell. This would be easier to code and maintain but might consume a little more memory.
You R making reUsable identifier as only once . Do something like this :
-(UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString* identifier;
if(indexPath.section == 0)
identifier = #"0";
else
identifier = #"1";
self.tableView.dataSource = self;
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];
if( cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
if (indexPath.section == 0)
{
if(cell == nil)
{
cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:#"CommitteeCell" owner:self options:nil] objectAtIndex:0];
}
if (indicator == 1)
{
cell.lblName.text = str;
}
else
{
cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];
}
cell.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell.backgroundView).image = img;
return cell;
}
Use like follow its work in my code smoothly , if you need more help let me know :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(YOUR CONDITION HERE)
ShareActionViewCell *shareCell;
NSString *ShareCellId = [NSString stringWithFormat:#"ShareCell%d",indexPath.row];
shareCell = (ShareActionViewCell *)[tableView dequeueReusableCellWithIdentifier:ShareCellId];
if(!shareCell) {
shareCell = [[ShareActionViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ShareCellId];
}
shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
shareCell.ShareTitle.text = [NSString stringWithFormat:#"%#",[tbldata objectAtIndex:indexPath.row]];
} else {
CustCell *dataCell;
NSString *DataCellId = [NSString stringWithFormat:#"DataCell%d",indexPath.row];
dataCell = (CustCell *)[tableView dequeueReusableCellWithIdentifier:DataCellId];
if(!dataCell) {
dataCell = [[CustCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DataCellId];
}
shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
shareCell.ShareTitle.text = [NSString stringWithFormat:#"%#",[tbldata objectAtIndex:indexPath.row]];
}
}
Suggested using -objectForKey for a Dictionary:
[[dic objectForKey:#"post"] objectAtIndex:8];
Make sure there is a NSArray object at name/post/ pic keyed to dic
And, in your for loop:
for(int i=0;i<[dic count]-1;i++)
{
[arrayName addObject:[[dic valueForKey:#"name"] objectAtIndex: i]];
[arrayPost addObject:[[dic valueForKey:#"post"]objectAtIndex:i]];
[arrayimage addObject:[[dic valueForKey:#"pic"]objectAtIndex:i]];
}
are you sure [dic count] <= [dic objectForKey:#"name"]?
add a nil to array will be crashed.
4.Where did you call the method -(void)NewsParser:(NSMutableDictionary *)dic;, If your data array is correct, maybe the [table1 reloadData]; crashed.

how to add 5 different custom cells in tableView

I want to show different data from web in my tableview but I am not getting how to show them in separate cells in one section of a table can any one help me to show
in one cell
cell.textLabel.text=app.i_name;
in second cell
cell.textLabel.text=app.i_phone;
in third cell
cell.textLabel.text=app.i_hours;
in forth cell
cell.textLabel.text=app.i_address;
in fifth cell
cell.textLabel.text=app.i_email;
my cell for row at index is as
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Single Cell";
SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"SingleCell" bundle:nil];
cell = (SingleCell *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:[indexPath row]];
//cell.namelbl.text=application.application_name;
return cell;
}
Try this code :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Single Cell";
SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"SingleCell" bundle:nil];
cell = (SingleCell *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:[indexPath row]];
//cell.namelbl.text=application.application_name;
if (indexPath.row == 0)
{
cell.textLabel.text=application.i_name;
}
else if (indexPath.row == 1)
{
cell.textLabel.text = application.i_iphone;
}
else if (indexPath.row == 2)
{
cell.textLabel.text = application.i_hours;
}
else if (indexPath.row == 3)
{
cell.textLabel.text = application.i_address;
}
else
{
cell.textLabel.text = application.i_email;
}
return cell;
}
Hope this answer will help. Cheers
i solved this question by doing this code thanks for all giving suggestion
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellForInfo";
CellForInfo *cell =(CellForInfo *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"CellForInfo" bundle:nil];
cell = (CellForInfo *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:0];
if (indexPath.row == 0)
{
cell.lblinfo.text=application.i_name;
}
if (indexPath.row == 1)
{
cell.lblinfo.text = application.i_phone;
}
if (indexPath.row == 2)
{
cell.lblinfo.text = application.i_hours;
}
if (indexPath.row == 3)
{
cell.lblinfo.text = application.i_address;
}
if (indexPath.row == 4)
{
cell.lblinfo.text = application.i_email;
}
return cell;
}
IKQ's code example should work. But I suggest to try my TableKit library. This way the code will be more clear and elegant:
- (void)viewDidLoad
{
[super viewDidLoad];
TKStaticCell* nameCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Name" detailText:app.i_name];
TKStaticCell* phoneCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Phone" detailText:app.i_phone];
TKStaticCell* hoursCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Hours" detailText:app.i_hours];
TKStaticCell* addressCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Address" detailText:app.i_address];
TKStaticCell* emailCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"email" detailText:app.i_email];
TKSection* section = [TKSection sectionWithCells:nameCell, phoneCell, hoursCell, addressCell, emailCell, nil];
self.sections = [NSArray arrayWithObject:section];
}
Also the library allows to define custom cell instead of TKStaticCell.
You can use this code for short
CellForInfo * cellForInfo = (CellForInfo *)[tableView dequeueReusableCellWithIdentifier:nil];
if (cellForInfo ==nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CellForInfo" owner:self options:nil];
cellForInfo = [nib objectAtIndex:0];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self tableInfo];
}
- (void) tableInfo
{
NSArray *keysArray = #[#"CampaignsName",#"BusinessName",#"BusinessType",#"CampaignsType",#"Distance",#"Daysleft",#"CampaignImage",];
NSArray *valuesArray1 =[NSArray arrayWithObjects:#"5 % OFF ",#"Coffe Shop",#"1",#"1",#"0.10 Miles",#"5 days Left",#"b2.png", nil];
NSArray *valuesArray2 = [NSArray arrayWithObjects:#"win $2 for you & charity ",#"Red Tommato",#"2",#"2",#"20 Miles",#"2 days Left",#"b1.png", nil];
NSArray *valuesArray3 = [NSArray arrayWithObjects:#"Buy dogs food & get a one more",#"Pet Care",#"3",#"3", #"30 Miles",#"10 days Left",#"b2.png", nil];
NSArray *valuesArray4 =[NSArray arrayWithObjects:#"win $2 for you & charity ",#"Red Tommato",#"1",#"1",#"0.10 Miles",#"7 days Left",#"b2.png", nil];
NSDictionary *dict1 = [NSDictionary dictionaryWithObjects:valuesArray1 forKeys:keysArray];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjects:valuesArray2 forKeys:keysArray];
NSDictionary *dict3 = [NSDictionary dictionaryWithObjects:valuesArray3 forKeys:keysArray];
NSDictionary *dict4 = [NSDictionary dictionaryWithObjects:valuesArray4 forKeys:keysArray];
self.tableArray = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,dict4,dict3,dict1,dict4,dict2,nil];
NSLog(#"Array %#",tableArray);
[self.tableObj reloadData];
}
#pragma mark table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableCustomView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
- (UITableViewCell *)tableCustomView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *mainCell ;
static NSString *CellIdentifier1 = #"CustomCellIdentifier";
static NSString *CellIdentifier2 = #"CustomCellIdentifier2";
if (indexPath.row % 2 != 0)
{
CustomCell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell2 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell2" owner:self options:nil];
cell2 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell2.CampaignsNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsName"]];
cell2.BusinessNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessName"]];
cell2.DistanceLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Distance"]];
cell2.DaysleftLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Daysleft"]];
cell2.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessType"]] integerValue];
NSLog(#": %d",businessType);
switch (businessType)
{
case 1:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"RETL#2x.png"];
break;
case 2:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"BTY.png"];
break;
case 3:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t3.png"];
break;
case 2:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t2.png"];
break;
case 3:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
mainCell = cell2 ;
}
else
{
CustomCell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell1" owner:self options:nil];
cell1 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell1.CampaignsNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsName"]];
cell1.BusinessNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessName"]];
cell1.DistanceLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Distance"]];
cell1.DaysleftLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Daysleft"]];
cell1.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessType"]] integerValue];
NSLog(#": %d",businessType);
switch (businessType)
{
case 1:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"RETL#2x.png"];
break;
case 2:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"BTY.png"];
break;
case 3:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t3.png"];
break;
case 2:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t2.png"];
break;
case 3:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
mainCell = cell1 ;
}
return mainCell;
NSLog(#"Index Path is :%d %d", indexPath.section,indexPath.row);
}

Not calling Method didSelectRowAtIndexPath:

didSelectRowAtIndexPath: method is not calling even after connecting table delegate and DataSource to file owner.
when i am trying to print something it is not printing in this methods
find my code below for your reference:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [favorite count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell= nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"mycell"];
if (cell == nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"mycell"];}
db * temp =(db *)[self.favorite objectAtIndex:indexPath.row];
cell.textLabel.text=temp.name;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"b");
UITableViewCell *selectedCell = [secondTable cellForRowAtIndexPath:indexPath];
[secondTable.delegate tableView:secondTable didSelectRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(#"%#",cellText);
[fav addObject:cellText];
arrayTwo = tableTw.tableTwo;
msg = [NSString stringWithFormat: #" %# ",[arrayTwo objectAtIndex:0]];
NSLog(#"%#",[arrayTwo objectAtIndex:0]);
}
-(void)checkAndCreateDatabase{
BOOL success;
NSFileManager *fileManager=[NSFileManager defaultManager];
success=[fileManager fileExistsAtPath:databasePath];
if(success)
return;
NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}
-(IBAction)resPage:(id)sender{
NSLog(#"%#",fav);
sqlite3 *database;
favorite=[[NSMutableArray alloc]init];
if(sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK){
NSString *sql=[NSString stringWithFormat:#"SELECT name,item_country.id,text.text FROM country,item_country,text WHERE country.name ='%#' AND text.item = item_country.item AND country.id = item_country.id", cellText];
const char *sqlStatement = [sql UTF8String];;
sqlite3_stmt *compiledStatement;
NSLog(#"a");
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)==SQLITE_OK){
NSLog(#"A");
while (sqlite3_step(compiledStatement)==SQLITE_ROW) {
d=[NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 2) encoding:NSUTF8StringEncoding];
a= [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
db *info =[[db alloc]initWithText:(NSString *)d andAg:(NSString *)a];
[favorite addObject:info];
}
}
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
if(favorite.count >0){
txt.text = [NSString stringWithFormat:#"%# ", [favorite objectAtIndex:0] ];
}}
}
- (void)viewDidLoad {
{
databaseName=#"nobel10.db";
NSArray *documentPaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentDir = [documentPaths objectAtIndex:0];
databasePath=[documentDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
[super viewDidLoad];
if (tableOn == nil) {
tableOn = [[table1 alloc] init];
}
if (tableTw == nil) {
tableTw = [[table2 alloc] init];
}
if (tableThre == nil) {
tableThre = [[table3 alloc] init];
}
if (tableFou == nil) {
tableFou = [[table4 alloc] init];
}
[firstTable setDataSource:tableOn];
[secondTable setDataSource:tableTw];
[thirdTable setDataSource:tableThre];
[fourthTable setDataSource:tableFou];
[fifthTable setDataSource:tableFiv];
[firstTable setDelegate:tableOn];
[secondTable setDelegate:tableTw];
[thirdTable setDelegate:tableThre];
[fourthTable setDelegate:tableFou];
tableOn.view = tableOn.tableView;
tableTw.view = tableTw.tableView;
tableThre.view = tableThre.tableView;
tableFou.view = tableFou.tableView;
{fav=[[NSMutableArray alloc]init];
cellText =[[NSString alloc]init];
secondTable=[[UITableView alloc]init];
secondTable.delegate=self;
secondTable.dataSource=self;
secondTable.tag = 20;
[self.view addSubview:secondTable];
}
}
suggestions please !
I think secondTable isn't the object you work on.Make sure it.
Add in .h file and at the dalegate calling time call dataSource.
obj_TableView.delegate = self;
obj_TableView.dataSource = self;
Then try it.

Change NIB Size

Can some one show me how to change the nib frame width to match the UITableViewCell. Right now it's set for 320 when i edit the nib directly, but when i open it in Ipad, it's still 320 width.
- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)path {
PMID = nil;
NSString *str = [[NSString stringWithFormat:#"%#",[object URL]] stringByReplacingOccurrencesOfString:#"tt://actions/"
withString:#""];
NSArray *firstSplit = [str componentsSeparatedByString:#"/"];
NSString *number1 = [firstSplit objectAtIndex:0];
NSString *number2 = [firstSplit objectAtIndex:1];
TTTableViewCell* cell = (TTTableViewCell*) [self.tableView
cellForRowAtIndexPath:path];
NSArray *nib = nil;
if ([[[NSUserDefaults standardUserDefaults] objectForKey:#"Admin"] isEqualToString:#"Admin"]){
nib = [[NSBundle mainBundle] loadNibNamed:#"MenuView"
owner:self options:nil];
}else if ([[NSString stringWithFormat:#"%d",[number1 intValue]] isEqualToString:[NSString stringWithFormat:#"%#", [[NSUserDefaults standardUserDefaults] objectForKey:#"IDKey"]]]){
nib = [[NSBundle mainBundle] loadNibNamed:#"MenuView2"
owner:self options:nil];
}else{
nib = [[NSBundle mainBundle] loadNibNamed:#"MenuView3"
owner:self options:nil];
}
UIView *menuView = nil;
for (id object in nib) {
if ([object isKindOfClass:[UIView class]]) {
menuView = (UIView *) object;
}
}
[self showMenu:menuView forCell:cell animated:YES];
}