0

I will try to be more clear by providing code. The objective is to grab information from a plist. (a Title and a subtitle) and add this to a table. The following code works for me but does not allow me to delete any of the rows. I am trying to figure out a way to do this.

#import "RWTViewController.h"
#import "details.h"

@interface RWTViewController () {
    NSMutableArray *titleSubject;
    NSMutableDictionary *subTitleContent;
}

@end

@implementation RWTViewController
NSInteger counter;

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    counter = subTitleContent.count;

    return counter;
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    // retreive image

    UIImage *myImage = [UIImage imageNamed:@"unreadMessage"];
    [cell.imageView setImage:myImage];

    cell.textLabel.text = titleSubject[indexPath.row];

    // This could possibly be changed?
    cell.detailTextLabel.text = subTitleContent[titleSubject[indexPath.row]];

    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:     (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove the row from data model
    [titleSubject removeObjectAtIndex:indexPath.row];



    // Request table view to reload
    [tableView reloadData];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSURL *urlWeb = [[NSBundle mainBundle] URLForResource:@"messageinfo"       withExtension:@"plist"];
    subTitleContent = [NSDictionary dictionaryWithContentsOfURL:urlWeb];


    titleSubject = subTitleContent.allKeys; 
//this tells me incompatible pointer assigning nsmutablearray from array.. not sure if         there is another way to implement. 
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
invertedfjord
  • 362
  • 1
  • 12
  • 2
    It's not clear what you're asking since `-[NSDictionary allKeys]` returns an `NSArray` not an `NSDictionary` and yet you talk about your dictionary becoming non-mutable. If jbouaziz answer isn't correct (and even if it is) you should clarify your question. – David Berry Aug 14 '14 at 15:32

2 Answers2

0

If I understand your question correctly, then this should do the trick.

NSDictionary *dictionary = someInfo;

NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithDictionary:dictionary];

You should set a dictionary to a mutable dictionary via alloc init if you are just creating it.

Jeremy H
  • 452
  • 7
  • 20
0

Try making a mutable copy of your dictionary keys:

NSMutableArray *mutablearray = moreDetails.allKeys.mutableCopy
jbouaziz
  • 1,484
  • 1
  • 12
  • 24