0
votes

I try that code but it crashs in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method cell.adLabel.text=[array objectAtIndex:[indexPath row]]; line.

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

static NSString *CellIdentifier = @"Cell" ;

Custom *cell = (Custom *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell=nil;

if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"Custom" owner:self options:nil];
    cell = satir;
}


// Configure the cell.
cell.adLabel.text=[array objectAtIndex:[indexPath row]];
cell.adLabel.textColor=   [UIColor darkGrayColor];
cell.adLabel.font = [UIFont systemFontOfSize:15];

cell.adresTextView.text=[array2 objectAtIndex:[indexPath row]];
cell.adresTextView.textColor=   [UIColor darkGrayColor];
cell.adresTextView.font = [UIFont systemFontOfSize:13];

cell.telefonLabel.text=[array3 objectAtIndex:[indexPath row]];
cell.telefonLabel.textColor=   [UIColor darkGrayColor];
cell.telefonLabel.font = [UIFont systemFontOfSize:13];


return cell;


}

- (IBAction)tablodaGosterBtnClick:(id)sender {

NSUInteger numComponents = [[pickerView dataSource] numberOfComponentsInPickerView:pickerView];

NSMutableString * text = [NSMutableString string];
for(NSUInteger i = 0; i < numComponents; ++i) {
    selectedRow = [pickerView selectedRowInComponent:i];
    title = [[pickerView delegate] pickerView:pickerView titleForRow:selectedRow forComponent:i];
    [text appendFormat:@"Selected item \"%@\" in component %lu\n", title, i];
}
if ([title isEqualToString:@"Restaurant"]) {

    array = [[NSMutableArray alloc] initWithObjects:@"Ehl-i Keyf Cafe", @"Enginarcı Mini Hotel ",@"Ginza Cafe",@"Lins Cafe",@"Opera Patisserie & Cafe",@"Patsa Cafe ",@"Sita Balık Evi ",nil];

    array2 = [[NSMutableArray alloc] initWithObjects:@"Fulya Mah. Mevlüt Pehlivan Cad. Erdoğanlar İş Merkezi No:14 Şişli/İstanbul",@"Fulya Mah. Mevlüt Pehlivan Sok. No:6 Fulya/İstanbul",@"Fulya Mah. Mevlüt Pehlivan Sok. No:13/A Şişli/İstanbul",@"Fulya Mah. Mevlüt Pehlivan Sok. No:13/A Şişli/İstanbul",@"Mevlüt Pehlivan Cad. No:25/2 Şişli/İstanbul",@"Fulya Mah. Mevlüt Pehlivan Sok. Multinet Plaza No:12 Şişli/İstanbul",@"Mevlüt Pehlivan Sok. No:9 Şişli/İstanbul", nil];

    array3 = [[NSMutableArray alloc] initWithObjects:@"0212 272 37 06",@"0536 304 33 28",@"0212 275 60 36",@"0212 204 15 15",@"0212 288 48 58",@"0212 336 88 00",@"0212 267 16 88", nil];

    [table reloadData];
}
else {

    [array removeAllObjects];
    [array2 removeAllObjects];
    [array3 removeAllObjects];
    [table reloadData];
}


}

How can I solve this? Is it possible, dissappear table view datas or delete?

3
What does the numberOfRowsInSection method look like ?user971401
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7; }Hacer Akac
problem here, 3 arrays as source for cells, you are emptying them in action method, and you always return constant number of cells.user971401

3 Answers

0
votes

Another option would be to not remove the item from the dataSource, but to modify the height for that row to hide it dynamically. You can do this by using - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath delegate method and [tableView reloadRowsAtIndexPaths:withRowAnimation]

0
votes
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

is called before the view shows so you won't get a chance to press the button and call

- (IBAction)tablodaGosterBtnClick:(id)sender

Therefore, you should move the array initialization to somewhere else. If you use array as data source of your table view, then a good place to go is

-(void)ViewDidLoad
0
votes
As per your comment

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 7;    //You need to replace your code here. You have to return whatever value in array and it must be same value count in all array which you are using.
}

if you return number of 7 and you are remove all value form array in 

- (IBAction)tablodaGosterBtnClick:(id)sender {

 //Remove value from array
}

when you reload tableview 

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

//Your code

cell.adLabel.text=[array objectAtIndex:[indexPath row]]; //Here Array is empty and you are try to get value from it so its crashing here.

//Your code
}