Reputation: 3212
I'm developing an app using Xcode 4.5 and iOS 5.0.
In my app, i have a UITableView
called surveyTableView created through Storyboard.
I want my surveyTableView cell
s selected and i'm using this piece of code to make it happen.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *cellIdentifier = @"Cell Identifier";
UITableViewCell *cell = [self.surveyTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.text = [[self.surveyInfoArray objectAtIndex:indexPath.row] valueForKey:@"SurveyName"];
[cell setSelected:YES];
return cell ;
}
I've only one section whose number of rows is 2 in this case. Here is the image what i got on the screen.
Do you guys any idea why this is happening ?
EDIT : I've set UITableView selection attribute
to Multiple Selection
, even if it's Single Line Selection
, i realized that there is no difference.
EDIT 2 : Here,i get image when ,i select UITableViewCellStyleSubtitle
EDIT 3 : Here is the interesting part, when i select right now, here is the image.That's driving me crazy
Upvotes: 0
Views: 186
Reputation: 590
I think you are not able to fetch the data from surveyTableView
NSString *cellValue= [[self.surveyInfoArray objectAtIndex:indexPath.row] valueForKey:@"SurveyName"];
NSLog(@"%@",cellValue);
check whether it's printing some values in console or not
Upvotes: 0
Reputation: 8460
for that You should use selectRowAtIndexPath:animated:scrollPosition:
instead selected property for UITableViewCell in cellForRowAtIndexPath
.
by using this one you can select a cell always , and only change when you select an another cell
Upvotes: 1
Reputation: 1081
I also had same problem, fixed it via setting attributes properly in storyboard. Attaching the screenshot of tableview properties. Hope this helps you
Upvotes: 0
Reputation: 1501
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
Upvotes: 0