Updated up my question
I've got a settings page where I am showing the setting name on the left, and what the current setting is on the right (UITableViewCellStyleValue1
). When you tap a setting's cell, you get an action sheet that lets you select "View All", "Yes", "No". My goal is to put the value they select into the right side of the cell so that they can see a change was made.
Action Sheet Event
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
thisVal = @"Show All";
NSLog(@"Button 0");
} else if (buttonIndex == 1) {
thisVal = @"Yes";
NSLog(@"Button 1");
} else if (buttonIndex == 2) {
thisVal = @"No";
NSLog(@"Button 2");
} else if (buttonIndex == 3) {
NSLog(@"Button 3");
}
[self saveSettings:thisKey :thisVal];
NSLog(@"Before: %@",[table2settings objectAtIndex:(NSUInteger)thisRow]);
if (thisSection == 0){
[table1settings replaceObjectAtIndex:(NSUInteger)thisRow withObject:thisVal];
}else{
[table2settings replaceObjectAtIndex:(NSUInteger)thisRow withObject:thisVal];
}
NSLog(@"After: %@",[table2settings objectAtIndex:(NSUInteger)thisRow]);
[self.tblView reloadData];
}
Because of the Before
and After
NSlog's, I can see that the actual array is being updated. But the tblView
does not reload. the data.
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier;
if (indexPath.row == 0 && indexPath.section == 0){
CellIdentifier = @"CellWithSwitch";
}else{
CellIdentifier = @"PlainCell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
if (indexPath.section == 0){
[[cell textLabel] setText:[table1labels objectAtIndex:indexPath.row]];
if (indexPath.row == 0 && indexPath.section == 0){
BOOL switchOn;
if ([[table1settings objectAtIndex:indexPath.row] isEqualToString: @"On"]){
switchOn = YES;
}else{
switchOn = NO;
}
switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchview setOn:switchOn animated:YES];
[switchview addTarget:self action:@selector(updateCurrentLocation) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchview;
}else{
if (![[table1settings objectAtIndex:indexPath.row] isEqualToString: @""]){
[[cell detailTextLabel] setText:[table1settings objectAtIndex:indexPath.row]];
}else{
[[cell detailTextLabel] setText:@""];
}
}
}else{
if (![[table2settings objectAtIndex:indexPath.row] isEqualToString: @""]){
[[cell detailTextLabel] setText:[table2settings objectAtIndex:indexPath.row]];
}else{
[[cell detailTextLabel] setText:@""];
}
[[cell textLabel] setText:[table2labels objectAtIndex:indexPath.row]];
}
return cell;
}
More information
Here's my .h file's @interface:
NSMutableArray *table1settings;
NSMutableArray *table2settings;
And under that:
@property (nonatomic, retain) NSMutableArray *table1labels;
@property (nonatomic, retain) NSMutableArray *table2labels;
And my .m file:
@synthesize table1settings;
@synthesize table2settings;
updateCurrentLocation
- (void)updateCurrentLocation {
switchview.on ? [self saveSettings:@"useLocation" :@"On"] : [self saveSettings:@"useLocation" :@"Off"];
NSLog(@"%@", [self loadSettings:@"useLocation"]);
}
More again
@interface DOR_FiltersViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
UITableView *tblView;
@property (nonatomic, retain) UITableView *tblView;
@synthesize tblView;
Also, for @implementation DOR_FiltersViewController
, I am getting a warning saying "Incomplete implementation". I have no clue what that generic statement could possibly mean. Tried looking it up, and it almost seems like it could mean anything.
The Fix
First, I found that I did not have tblView connected to my table view. -.- I had to right-click the table view and drag it to my .h file and link it to tblView. I thought I had already done this. I feel very foolish now. Then, for the @interface, I had to use __weak IBOutlet UITableView *tblView;
, and under that @property (weak, nonatomic) IBOutlet UITableView *tblView;
Then it all worked.