मैं डिफ़ॉल्ट रूप से चुनी गई पंक्ति कैसे सेट कर सकता हूं? मैं एक पंक्ति का चयन करना चाहता हूं, indexpath.row
के साथ चयनित पंक्ति की संख्या ले लो और फिर तालिका को फिर से लोड करें और चयनित पंक्ति का चयन करें। कृपया क्या कोई मेरी मदद कर सकता है? क्या मुझे एक विधि में चयनित पंक्ति मिल सकती है - (IBAction
) segmentedControlIndexChanged
? didSelectRowAtIndexPath
में नहीं?UITableView में डिफ़ॉल्ट रूप से पुनः लोड करने के बाद चयनित पंक्तियों को कैसे याद रखें और उन्हें बनाए रखें?
यह अगर यह मदद कर सकते हैं समझने के लिए
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 100, 20) ];
// Configure the cell...
NSString *depdateChoosed=[deparatureDates objectAtIndex:depSelectedIndice];
NSString *comeateChoosed=[deparatureDates objectAtIndex:comSelectedIndice];
NSString *choosedDate =[NSString stringWithFormat:@"%@%@",depdateChoosed, comeateChoosed];
NSLog(@"date choisi %@ ",choosedDate);
if(segment.selectedSegmentIndex==0)
{
cell.textLabel.text =[deparatureDates objectAtIndex:indexPath.row];
}
else if(segment.selectedSegmentIndex==1) {
//cell.textLabel.text =[goingBackDates objectAtIndex:indexPath.row];
//cell.textLabel.text=[goingBackDates objectAtIndex:indexPath.row];
cell.textLabel.text =[goingBackDates objectAtIndex:indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@" champ séléctionner : %d ",indexPath.row);
if(segment.selectedSegmentIndex==0)
{
depSelectedIndice=indexPath.row;
}
else if(segment.selectedSegmentIndex==1) {
comSelectedIndice=indexPath.row;
}
//[tableView reloadData];
}
-(IBAction) segmentedControlIndexChanged
{
int i;
switch (self.segment.selectedSegmentIndex)
{
case 0:
i=0;
[tableView reloadData];
break;
case 1:
i=1;
NSLog(@"dexieme segment selectionner");
[tableView reloadData];
default:
break;
}
}
विधि NSIndexPath indexPath = [tableView indexPathForSelectedRow]; int वापस नहीं कर सकते हैं? – user567
टाइपो, क्षमा करें। यह एक सूचकांक पथ के लिए एक सूचक है। –
साथ ही, सुनिश्चित करें कि आपके 'UITableViewController' पर 'clearsSelectionOnViewWillAppear' को' NO' पर सेट किया गया है, अन्यथा यह दिखाई देने पर पंक्ति को स्वचालित रूप से अचयनित कर देगा। यह मुझे घंटों तक परेशान कर रहा था। – cheeesus