Get values from a plist file in iOS - ios

I am creating a Plist file as shown below
I want to list all the Items where level is 1 and I can only use accessoryType = UITableViewCellAccessoryCheckmark if level is 1. How can I do it.
I am loading my plist file here:
- (void)viewDidLoad
{
[super viewDidLoad];
countId = 0;
NSDictionary *dict=[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Topic" ofType:#"plist"]];
self.items=[dict valueForKey:#"Items"];
self.itemsInTable=[[NSMutableArray alloc] init];
[self.itemsInTable addObjectsFromArray:self.items];
[self.menuTableView registerNib:[UINib nibWithNibName:NSStringFromClass([IndicatorTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([IndicatorTableViewCell class])];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc]
initWithTitle:#"Done"
style:UIBarButtonItemStylePlain
target:self
action:#selector(doneSelection:)];
[self.navigationItem setRightBarButtonItem:myButton];
}
My code for cellForRowAtIndexpath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *Title= [[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:#"Name"];
return [self createCellWithTitle:Title image:[self.itemsInTable objectAtIndex:indexPath.row] indexPath:indexPath];
}
My code for didSelectRowAtIndexPath is :
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dic=[self.itemsInTable objectAtIndex:indexPath.row];
if([dic valueForKey:#"SubItems"])
{
NSArray *arr=[dic valueForKey:#"SubItems"];
BOOL isTableExpanded=NO;
for(NSDictionary *subitems in arr )
{
NSInteger index=[self.itemsInTable indexOfObjectIdenticalTo:subitems];
isTableExpanded=(index>0 && index!=NSIntegerMax);
if(isTableExpanded) break;
}
if(isTableExpanded)
{
[self CollapseRows:arr];
}
else
{
NSUInteger count=indexPath.row+1;
NSMutableArray *arrCells=[NSMutableArray array];
for(NSDictionary *dInner in arr )
{
[arrCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.itemsInTable insertObject:dInner atIndex:count++];
}
[self.menuTableView insertRowsAtIndexPaths:arrCells withRowAnimation:UITableViewRowAnimationLeft];
}
}
if([[[dic valueForKey:#"SubItems"]objectAtIndex:0]objectForKey:#"level"])
{
// NSArray *arr=[dic valueForKey:#"SubItems"];
// if ([[arr objectAtIndex:0 ] intValue] == #"1")
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
if(countId <5)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
countId = countId + 1;
}
else
{
UIAlertView *dialog;
dialog =[[UIAlertView alloc] initWithTitle:#"Alert Message"
message:#"Select maximum 5 countries"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK",nil];
[dialog show];
// NSLog(#"Greater then 5");
}
}
else
{
if(countId>0)
{
cell.accessoryType = UITableViewCellAccessoryNone;
countId--;
}
else
{
//show alert
UIAlertView *dialog;
dialog =[[UIAlertView alloc] initWithTitle:#"Alert Message"
message:#"Select atleast 1 country"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK",nil];
[dialog show];
// NSLog(#"must choose 1");
}
}
// countId = [self.tableView indexPathsForSelectedRows].count;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
}
Please do reply. I am stuck here

To check level = 1 to add accessoryType = UITableViewCellAccessoryCheckmark try
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *itemDictionary = [self.itemsInTable objectAtIndex:indexPath.row];
NSArray *subItems = [itemDictionary valueForKey:#"SubItems"];
NSDictionary *firstItem = subItems[0];
if ([[firstItem objectForKey:#"level"] integerValue] == 1) {
//Set appropriate accessory view here
} else {
//Check the cell accessory type and update this too
//This is to avoid wrong accessory view on cell reuse
}
}

You can use the following code to get the root object, then go from there:
NSDictionary *rootDict = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"Root"];

Related

how to plus and minus when button is clicked in uitabelview row and section and reload like foodpanda

I am creating app link food panda.let me explain the flow.I have a vc with table with rows and sections when i click on section it will expand and collapsing rows.in the section there is add button in each rows.wqhen i click on add button in section 3 row the button should hide and + and - button should show like the image given below.
2.when i click on the pluse and minus button it should add to cart and money should increase and decrease amount in cart i used below code for expand and collapse sections.
#implementation menulistingVC
- (void)viewDidLoad {
[super viewDidLoad];
[super viewDidLoad];
menuarray=[[NSMutableArray alloc]init];
arrselectedrow=[[NSMutableArray alloc]init];
defaults = [NSUserDefaults standardUserDefaults];
apiCall = [[APICall alloc]init];
isMultipleExpansionAllowed = NO;
arrSelectedSectionIndex = [[NSMutableArray alloc] init];
if (!isMultipleExpansionAllowed) {
[arrSelectedSectionIndex addObject:[NSNumber numberWithInt:countt+20]];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(loadtable:)
name:#"array" object:nil];
_tblview.estimatedRowHeight = 69;
_tblview.rowHeight = UITableViewAutomaticDimension;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadtable:(NSNotification*)notification
{
isMultipleExpansionAllowed = NO;
arrSelectedSectionIndex = [[NSMutableArray alloc] init];
if (!isMultipleExpansionAllowed) {
[arrSelectedSectionIndex addObject:[NSNumber numberWithInt:countt+20]];
}
[self getingfooddeatilsbacedonclub:[notification object]];
}
-(void)getingfooddeatilsbacedonclub:(NSString *)typestr{
_clubstr = [[NSUserDefaults standardUserDefaults]
stringForKey:#"newclubid"];
// accessToken=[defaults valueForKey:#"accessToken"];
// clubberId = [defaults valueForKey:#"idClubber_dtls"];
if (![APICall hasNetwork])
{
[Util displayToastMessage:#"No internet connection"];
}else
{
[customBezelActivityView activityViewForView:self.view];
NSString *urlstr = [NSString stringWithFormat:#"%s/presignin/menu/list/category/by_venue?clubId=%#&type=%#",urlPath,_clubstr,typestr];
NSLog(#"getherd :%#",urlstr);
[apiCall getArrayFromApiwithstauscode:urlstr restfulType:kRestfulGet andUseContentType:NO withRequestBody:nil completionHandler:^(NSArray *result, NSInteger statuscodeint){
NSLog(#"classifieds List response:%#",result);
NSLog(#"statuscode List response:%ld",(long)statuscodeint);
if (statuscodeint==200) {
dispatch_async(dispatch_get_main_queue(), ^{
[customBezelActivityView removeViewAnimated:YES];
menuarray=[result mutableCopy];
isMultipleExpansionAllowed = NO;
if (!isMultipleExpansionAllowed) {
[arrSelectedSectionIndex addObject:[NSNumber numberWithInt:countt+20]];
}
[_tblview reloadData];
});
}else if (statuscodeint==401){
dispatch_async(dispatch_get_main_queue(), ^{
[customBezelActivityView removeViewAnimated:YES];
UIStoryboard *storyBoard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
SignInViewController *SignINViewController=[storyBoard instantiateViewControllerWithIdentifier:#"SignINViewController"];
[self presentViewController:SignINViewController animated:YES completion:nil];
});
}
}];
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return menuarray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
NSArray *arr=[menuarray[section] valueForKey:#"menu"];
return arr.count;
}else{
return 0;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"MenudetailsTblCell";
menudetailscell = ( MenudetailsTblCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (menudetailscell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"MenudetailsTblCell" owner:self options:nil];
menudetailscell = [nib objectAtIndex:0];
}
if (menudetailscell == nil)
{
menudetailscell = [[MenudetailsTblCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
menudetailscell.detailview.layer.cornerRadius = 3.0;
menudetailscell.detailview.layer.masksToBounds = YES;
if (indexPath.row==0) {
menudetailscell.toplbl.hidden=YES;
}else{
menudetailscell.toplbl.hidden=NO;
}
menudetailscell.addbtntocart.layer.cornerRadius = 5.0;
menudetailscell.addbtntocart.layer.masksToBounds = YES;
menudetailscell.addbtntocart.tag=indexPath.row;
menudetailscell.plusebtn.tag=indexPath.row;
menudetailscell.minusbtn.tag=indexPath.row;
menudetailscell.plusebtn.hidden=YES;
menudetailscell.minusbtn.hidden=YES;
menudetailscell.noofitemslbl.hidden=YES;
NSArray *arr=[menuarray[indexPath.section] valueForKey:#"menu"];
menudetailscell.typelbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:#"name"];
menudetailscell.describtionlbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:#"description"];
NSString *cost=[NSString stringWithFormat:#"%#%#",[[arr objectAtIndex:indexPath.row]valueForKey:#"price"],#".00"];
NSString *imgid=[NSString stringWithFormat:#"%#",[[arr objectAtIndex:indexPath.row]valueForKey:#"idmenus"]];
NSString *tax=[NSString stringWithFormat:#"%#",[[arr objectAtIndex:indexPath.row]valueForKey:#"tax"]];
if ([tax isEqualToString:#"tax"]) {
menudetailscell.taxlbl.text=#"(*Inclusive of all taxes)";
}else{
menudetailscell.taxlbl.text=#"(*Exclusive of all taxes)";
}
menudetailscell.ratelbl.text=[NSString stringWithFormat:#"%# %#",[[arr objectAtIndex:indexPath.row]valueForKey:#"country"],cost];
[ menudetailscell.addbtntocart addTarget:self action:#selector(addbtnclicked:)forControlEvents:UIControlEventTouchUpInside];
NSString *typeimgUrl1 = [NSString stringWithFormat:#"%s/presignin/menu/showMedia?idMenu=%#",urlPath,imgid];
NSURL *imageURL=[NSURL URLWithString:typeimgUrl1];
menudetailscell.imgview.imageURL=imageURL;
[menudetailscell.plusebtn addTarget:self action:#selector(pluseTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
[menudetailscell.minusbtn addTarget:self action:#selector(minusTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
menudetailscell.selectionStyle = UITableViewCellSelectionStyleNone;
return menudetailscell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *CellIdentifier = #"Menusectioncell";
menusectioncell = ( Menusectioncell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (menusectioncell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"Menusectioncell" owner:self options:nil];
menusectioncell = [nib objectAtIndex:0];
}
if (menusectioncell == nil)
{
menusectioncell = [[Menusectioncell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
// right-arrow //down-arrow
menusectioncell.Sectiomtitlebtn.selected = YES;
menusectioncell.dotlbl.hidden=NO;
menusectioncell.expandtypeimg.image=[UIImage imageNamed:#"down-arrow"];
}
else{
menusectioncell.dotlbl.hidden=YES;
menusectioncell.expandtypeimg.image=[UIImage imageNamed:#"right-arrow"];
}
menusectioncell.Sectiomtitlebtn.tag=section;
menusectioncell.dotlbl.layer.cornerRadius = menusectioncell.dotlbl.frame.size.height/2;
menusectioncell.dotlbl.layer.masksToBounds = YES;
[menusectioncell.Sectiomtitlebtn addTarget:self action:#selector(btnTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
NSString *btntitle=[menuarray[section] valueForKey:#"catagory"];
itemarr=[menuarray[section] valueForKey:#"menu"];
NSString *items=[itemarr[0] valueForKey:#"name"];
menusectioncell.sectiontitleilb.text=btntitle;
if (itemarr.count==1) {
menusectioncell.itemslbl.text=[NSString stringWithFormat:#"%#",items];
}else{
NSString *seconditemstr=[itemarr[1] valueForKey:#"name"];
menusectioncell.itemslbl.text=[NSString stringWithFormat:#"%#,%# etc..",items,seconditemstr];
}
menusectioncell.selectionStyle = UITableViewCellSelectionStyleNone;
return menusectioncell.contentView;
}
-(IBAction)btnTapShowHideSection:(UIButton*)sender
{
int section=sender.tag;
if (!sender.selected)
{
//originallcode
if (!isMultipleExpansionAllowed) {
[arrSelectedSectionIndex addObject:#"-1"];
[arrSelectedSectionIndex replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:sender.tag]];
}else {
NSLog(#"%#",arrSelectedSectionIndex);
[arrSelectedSectionIndex addObject:[NSNumber numberWithInteger:sender.tag]];
}
menusectioncell.dotlbl.hidden=YES;
menusectioncell.expandtypeimg.image=[UIImage imageNamed:#"right-arrow"];
sender.selected = YES;
}
else{
sender.selected = NO;
menusectioncell.dotlbl.hidden=NO;
menusectioncell.expandtypeimg.image=[UIImage imageNamed:#"down-arrow"];
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:sender.tag]])
{
[arrSelectedSectionIndex removeObject:[NSNumber numberWithInteger:sender.tag]];
}
}
if (!isMultipleExpansionAllowed) {
[_tblview reloadData];
}else {
[_tblview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)addbtnclicked:(UIButton *)sender
{
menudetailscell.plusebtn.hidden=NO;
menudetailscell.minusbtn.hidden=NO;
menudetailscell.noofitemslbl.hidden=NO;
menudetailscell.addbtntocart.hidden=YES;
int rowselect=sender.tag;
[arrselectedrow addObject:[NSNumber numberWithInteger:sender.tag]];
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:sender.tag inSection:sectionselect];
[self.tblview beginUpdates];
[self.tblview reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tblview endUpdates];
}
- (void)pluseTapShowHideSection:(UIButton *)sender
{
}
- (void)minusTapShowHideSection:(UIButton *)sender
{
if ([arrselectedrow containsObject:[NSNumber numberWithInteger:sender.tag]])
{
[arrselectedrow removeObject:[NSNumber numberWithInteger:sender.tag]];
}
[self.tblview beginUpdates];
[self.tblview reloadRowsAtIndexPaths:[NSArray arrayWithObjects:arrselectedrow, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tblview endUpdates];
}

Pass UILabel text from UITableViewCell to a different function

I've tried searching around for an answer, but have not succeeded in doing so.
I want to pass the text in one of the UILabel's the cell holds. I am not entirely sure on how to do this. I am trying to pass the content of one of the UILabels into the swipeTableViewCell didTriggerRightUtilityWithIndex function, as I am using SWTableViewCell.
The table is populated with items from a mysql table.
This is my current UITableViewCell function:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
if([taskArray valueForKey:#"TaskData"] != [NSNull null])
{
GroupDataTableViewCell *cell = (GroupDataTableViewCell*)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:#"Les mer"];
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate = self;
if (cell == nil) {
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableItem" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *item = [taskArray objectAtIndex:indexPath.row];
if([item objectForKey:#"TaskID"] != [NSNull null])
cell.numberTextField.text = [item objectForKey:#"TaskID"];
if([item objectForKey:#"Title"] != [NSNull null])
cell.titleTextField.text = [item objectForKey:#"Title"];
if([item objectForKey:#"Description"] != [NSNull null])
cell.descriptionTextField.text = [item objectForKey:#"Description"];
if([[selfArray valueForKey:#"CheckStat"] isEqualToString:#"(null)"])
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else if([[selfArray valueForKey:#"CheckStat"] length] == 0)
{
if ([[item objectForKey:#"CheckStat"] containsString:#"1"])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
for(int i = 0; i < [[[selfArray valueForKey:#"CheckStat"] componentsSeparatedByString:#","] count]; i++)
{
NSString *checkedNumStr = [[[selfArray valueForKey:#"CheckStat"] componentsSeparatedByString:#","] objectAtIndex:i];
//if (i >= [taskArray count] || [checkedNumStr intValue] >= [taskArray count])
//break;
if ([checkedNumStr intValue] == indexPath.row + 1)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
}
else
return nil;
}
I want to send the cell.descriptionField.text from there to this code, when the rightUtilityButton is activated:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Bookmark" message:#"Description" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
So, I want the cell.descriptionTextField.text from the first snippet into the second snippet. I am not entirely sure on how to do this, as I am not good with tablecells. I want the cell.descriptionTextField.text from the first snippet to show up in the alertView as the description.
Save your [item objectForKey:#"Description"] into an NSMutableArray previously created, if you order your cells with the same order as the nsmutablearray, you could access this value into your wanted function like this:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
NSString *desc = [myarray objectAtIndex:index];
// Use your string wherever you want
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Bookmark" message:#"Description" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
Why don't you just store those text in NSString* property within your class and then use wherever you need?
Do not store information in cell object rather than that use datasource to store information.
using index you can get the respective information that was stored in label
In your case you are storing description in label which can be later retrieved as follows
-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
NSDictionary *item = [taskArray objectAtIndex:index;
//Do something with the item
}

Select All,Deselect All and select particular cell in custom table view

I have created a drop-down using table cell,where i am showing my data. My data is get display in drop down.Now I want all the cell should be selected initially. Also I want to deselect all cell, and individual cell.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView isEqual:expansionTableView]) {
forState:UIControlStateNormal];
if (indexPath.row == 0) {
if ([indexPath isEqual:self.selectIndex]) {
self.isOpen = NO;
[self didSelectCellRowFirstDo:NO nextDo:NO];
self.selectIndex = nil;
}else
{
if (!self.selectIndex) {
self.selectIndex = indexPath;
[self didSelectCellRowFirstDo:YES nextDo:NO];
}else
{
[self didSelectCellRowFirstDo:NO nextDo:YES];
}
}
}else
{
objectForKey:#"surveyName"];
NSMutableArray *list=[[NSMutableArray alloc]init];
NSMutableArray *idlist =[[NSMutableArray alloc]init];
for (int i=0; i<_arraySurveyName.count; i++) {
NSMutableDictionary *dict=[_arraySurveyName objectAtIndex:i];
NSString *surveyName=[dict valueForKey:#"SurveyName"];
NSString *surveyID =[dict valueForKey:#"SurveyId"];
[list addObject:surveyName];
[idlist addObject:surveyID];
}
NSString *item = [list objectAtIndex:indexPath.row-1];
NSNumber *item1= [idlist objectAtIndex:indexPath.row-1];
str = item1;
NSLog(#"%#",str);
[_btn_surveyName setTitle:item forState:UIControlStateNormal];
[expansionTableView setHidden:YES];
}
}
else if ([tableView isEqual:expansionTableViewQtn]){
NSString *selectedQuestion=[arrayOfQuestionDetail objectAtIndex:indexPath.section];
[expansionTableViewQtn setHidden:YES];
[_btn_showQuestn setTitle:selectedQuestion forState:UIControlStateNormal];
}
}
it's my code for "didSelect".How to do this.
You can use below methods to select and deselect the cells
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
[tableView deselectRowAtIndexPath:indexPath animated:NO];//For deselecting
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];//For selecting

Replacing one NSMutableDictionary object in NSMutableArray, replaces all objects

I am fairly knew to iOS development and I think I jumped into the deep end too fast.
I am trying to replace a NSMutableDictionary inside an NSMutableArray of dictionaries by using replaceObjectAtIndex:withObject: but when I reload my tableView, all the objects in the array have been replaced by the one I am trying to replace,not just the specific index.
Thanks in advance for your help.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
if ((self.editing && indexPath.row == [detailsArray count])) {
cell.textLabel.text = #"Add Detail";
return cell;
}
[cell.textLabel setText:[[detailsArray objectAtIndex:indexPath.row] objectForKey:#"name"]];
[cell.detailTextLabel setText:[[detailsArray objectAtIndex:indexPath.row] objectForKey:#"desc"]];
return cell;
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
if (!editing) {
[dictionaryList setValue:name.text forKey:#"name"];
[dictionaryList setValue:description.text forKey:#"desc"];
[detailsArray replaceObjectAtIndex:IndexHelper.row withObject:dictionaryList];
}
[self.tableView reloadData];
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
if ([detailsArray count] > 0) {
[detailsArray removeObjectAtIndex:indexPath.row];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
[dictionaryList setValue:#"Title" forKey:#"name"];
[dictionaryList setValue:#"Details" forKey:#"desc"];
[detailsArray addObject:dictionaryList];
[[self tableView] endUpdates];
[[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
IndexHelper = indexPath;
UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:#"" message:#"\n\n\n\n"
delegate:self cancelButtonTitle:#"Άκυρο" otherButtonTitles:#"Αποθήκευση", nil];
UIImageView *passwordImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"passwordfield" ofType:#"png"]]];
passwordImage.frame = CGRectMake(11,20,262,33);
[passwordAlert addSubview:passwordImage];
name = [[UITextField alloc] initWithFrame:CGRectMake(16,25,252,21)];
name.font = [UIFont systemFontOfSize:18];
name.backgroundColor = [UIColor whiteColor];
name.secureTextEntry = NO;
name.keyboardAppearance = UIKeyboardAppearanceAlert;
name.delegate = self;
name.placeholder = #"Title";
[name becomeFirstResponder];
[passwordAlert addSubview:name];
UIImageView *passwordImage2 = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"passwordfield" ofType:#"png"]]];
passwordImage2.frame = CGRectMake(11,65,262,33);
[passwordAlert addSubview:passwordImage2];
description = [[UITextField alloc] initWithFrame:CGRectMake(16,70,252,21)];
description.font = [UIFont systemFontOfSize:18];
description.backgroundColor = [UIColor whiteColor];
description.secureTextEntry = NO;
description.keyboardAppearance = UIKeyboardAppearanceAlert;
description.delegate = self;
description.placeholder = #"Details";
[description becomeFirstResponder];
[passwordAlert addSubview:description];
[passwordAlert show];
}
---This is where I am replacing the dictionary in the array---
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if (buttonIndex==1) {
if ([name.text isEqualToString:#""] && [description.text isEqualToString:#""]) {
return;
}
[dictionaryList setValue:name.text forKey:#"name"];
[dictionaryList setValue:description.text forKey:#"desc"];
[detailsArray replaceObjectAtIndex:indexPath.row withObject:dictionaryList];
}
[self.tableView reloadData];
NSLog(#"%#",detailsArray);
}
I think you are adding same dictionary at all the indexes to it takes a common reference you have to check and make multiple instances for the dictionary for each index.
It may help you
I think the problem lies in the first of the code below
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; //REMOVE THIS LINE
NSIndexPath *indexPath = IndexHelper; //USE THIS LINE
if (buttonIndex==1) {
if ([name.text isEqualToString:#""] && [description.text isEqualToString:#""]) {
return;
}
[dictionaryList setValue:name.text forKey:#"name"];
[dictionaryList setValue:description.text forKey:#"desc"];
[detailsArray replaceObjectAtIndex:indexPath.row withObject:dictionaryList];
}
[self.tableView reloadData];
NSLog(#"%#",detailsArray);
}

Unrecognized selector sent. Objective-C error

I am writing a google reader application and have been trying to create the settings table view with UISwitch. Below is the complete code sequence:
#implementation Settings
#synthesize rowImage;
#synthesize ViewPushed;
#synthesize alreadySignedIn;
#synthesize syncStartupSwitch;
#synthesize confirmMarkSwitch;
#synthesize landscapeModeSwitch;
#synthesize appBadgeSwitch;
#synthesize fontSwitch;
#synthesize newItemsSwitch;
#pragma mark -
#pragma mark View lifecycle
static SEL syncStartup;
static SEL markAsReadConfirm;
static SEL landscapeMode;
static SEL appBadge;
static SEL fontSettings;
static SEL newItemsFirstSel;
+(void) initialize{
syncStartup = #selector(syncAtStartup:);
markAsReadConfirm = #selector (confirmMarkAsRead:);
landscapeMode = #selector (landscapeMode:);
appBadge = #selector (appBadgeSetting:);
fontSettings = #selector (largeFontSetting:);
newItemsFirstSel = #selector (newItemFirst:);
}
-(void) newItemFirst:(id)sender {
if ([sender isOn]) {
newItemsSwitch = YES;
}else {
newItemsSwitch = NO;
}
}
-(void) syncAtStartup:(id)sender {
if ([sender isOn]) {
syncStartupSwitch = YES;
}else {
syncStartupSwitch = NO;
}
}
-(void) confirmMarkAsRead:(id)sender{
if ([sender isOn]) {
confirmMarkSwitch = YES;
}else {
confirmMarkSwitch = NO;
[self.tableView reloadData];
}
}
-(void) landscapeMode:(id)sender{
if([sender isOn]) {
landscapeModeSwitch = YES;
}else {
landscapeModeSwitch = NO;
}
}
-(void) appBadgeSetting:(id)sender{
if([sender isOn]) {
appBadgeSwitch = YES;
}else {
appBadgeSwitch = NO;
}
}
-(void) largeFontSetting:(id)sender{
if ([sender isOn]) {
[UIFont systemFontOfSize:32];
fontSwitch = YES;
NSLog(#"YES");
}else {
fontSwitch = NO;
NSLog(#"YES");
}
}
/*
-(void) saveLastViewedItem{
[plistData setValue:[[[UIApplication sharedApplication]delegate]currentItemID]forKey:keyLastItemID];
[plistData setValue:[[[[[[[UIApplication sharedApplication]delegate]navController]navController]topViewController]delegate]tag]forKey:keyLastItemTag];
}
-(void) save {
[self saveLastViewedItem];
BOOL success = [plistData writeToFile:[docsPath stringByAppendingPathComponent:plistName] atomically:YES];
if (!success) {
NSLog(#"FAILED saving plist");
}else {
dbg_s(#"saved data:%# to file: %#", plistData, [docsPath stringByAppendingPathComponent:plistName]);
}
}
-(void) load{
dbg(#"loading plist data from path: %#", [docsPath stringByAppendingPathComponent:plistName]);
plistData = [[NSMutableDictionary dictionaryWithContentsOfFile:[docsPath stringByAppendingPathComponent:plistName]]retain];
if(!plistData){
NSLog(#"FAILED loading plist");
plistData = [[NSMutableDictionary dictionary] retain];
}
dbg_s(#"Loaded plist data", plistData);
dbg_s("%#", plistData);
[self removeDeprecatedProperties];
[self loadFeedList];
}
-(void) removeDeprecatedProperties{
for (NSString * deprecatedProperty in deprecatedProperties){
[plistData removeObjectForKey:deprecatedProperty];
}
}
-(void) reloadFeedList{
[self loadFeedList];
[self setUIElements];
}
-(NSArray *) loadFeedList {
NSString *contents = [NSString stringWithContentsOfFile:[docsPath stringByAppendingPathComponent:#"tagList"]encoding:NSUTF8StringEncoding error:nil];
id result;
if(!contents) {
dbg(#"no feed list loaded");
result = nil;
}else {
NSArray *originalList = [contents componentsSeparatedByString:#"\n"];
NSMutableArray *feedList = [NSMutableArray arrayWithCapacity:[originalList count]];
for (NSString *feed in originalList) {
NSString *trimmedFeed = [feed stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([feed length] > 0){
[feedList addObject:trimmedFeed];
}
}
result = feedList;
}
[possibleTags release];
possibleTags = [result retain];
return result;
}
-(NSArray *)feedList {
return possibleTags;
}
-(NSArray *) activeTagList {
id tags = [self tagList];
NSArray *result = [NSMutableArray arrayWithCapacity:[tags count]];
for (NSString *tag in tags) {
if([possibleTags containsObject:tag]) {
[result arrayByAddingObject:tag];
}
}
return result;
}
-(id) init{
self =[super init];
plistName = #"config.plist";
if (openLinksInSegmentValues == nil)
openLinksInSegmentValues = [[NSArray alloc] initWithObjects:openLinksInAskMeValue, openLinksInSafariValue, openLinksIniReaderValue, nil];
if (deprecatedProperties == nil)
deprecatedProperties = [[NSArray alloc] initWithObjects:#"openInSafari", nil];
[self docsPath];
[self load];
return self;
}
*/
- (void)viewDidLoad {
syncSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
readSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
landscapeSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
badgeSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
largeFontSwitch=[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
newItemsFirstSwitch =[[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
//switcher = [[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
NSString *loginData;
NSError *keychainError;
NSString *checkUsername= [SFHFKeychainUtils getPasswordForUsername:#"Username" andServiceName:#"iReader" error:&keychainError];
NSString *checkPassword = [SFHFKeychainUtils getPasswordForUsername:#"Password" andServiceName:#"iReader" error:&keychainError];
if (checkPassword == nil || checkUsername == nil) {
alreadySignedIn = NO;
loginData = #"Sync Settings";
} else {
alreadySignedIn = YES;
loginData = #"Logout";
}
if(ViewPushed == NO) {
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
}
listOfItems = [[NSMutableArray alloc] init];
NSArray *syncSettingsToLoad = [NSArray arrayWithObjects:loginData, nil];
NSDictionary *syncSettingsToLoadDict = [NSDictionary dictionaryWithObject:syncSettingsToLoad forKey:#"Settings"];
NSArray *generalSetting = nil;
generalSetting = [NSArray arrayWithObjects:#"Sync at Startup",#"Confirm Mark as Read", #"Landscape Mode", #"Cache Settings",nil];
NSMutableDictionary *generalSettingsDict = [NSMutableDictionary dictionaryWithObject:generalSetting forKey:#"Settings"];
NSArray *appearanceSettings = [NSArray arrayWithObjects:#"New Items First", #"App Icon Badge", #"Large Font", nil];
NSDictionary *appearanceSettingsDict = [NSDictionary dictionaryWithObject:appearanceSettings forKey:#"Settings"];
NSArray *sharingSettings = [NSArray arrayWithObjects:#"Customize Sharing Options", nil];
NSDictionary *sharingSettingsDict = [NSDictionary dictionaryWithObject:sharingSettings forKey:#"Settings"];
NSArray *advancedSettings = [NSArray arrayWithObjects:#"Advanced Options", nil];
NSDictionary *advancedSettingsDict = [NSDictionary dictionaryWithObject:advancedSettings forKey:#"Settings"];
[listOfItems addObject:syncSettingsToLoadDict];
[listOfItems addObject:generalSettingsDict];
[listOfItems addObject:appearanceSettingsDict];
[listOfItems addObject:sharingSettingsDict];
[listOfItems addObject:advancedSettingsDict];
self.title =#"Settings";
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
[super viewDidLoad];
}
//defaultDatabase = [[userPrefs valueForKey:MAPref_DefaultDatabase] retain];
-(void) cancel_Clicked:(id)sender
{
[self.navigationController dismissModalViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
//[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return [listOfItems count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSDictionary *dictionary = [listOfItems objectAtIndex:section];
NSArray *array = [dictionary objectForKey:#"Settings"];
return [array count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:
(NSInteger) section {
if (section == 0) {
return #"Sync Settings";
}
if (section == 1) {
return #"General Options";
}
if (section == 2) {
return #"Appearance Options";
}
if (section == 3){
return #"Sharing Options";
}
if (section == 4){
return #"Advanced Options";
}
return nil;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(#"This is what we are looking for %# %#", checkUsername, checkPassword);
// Configure the cell...
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array =[dictionary objectForKey:#"Settings"];
NSString * cellValue = [array objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (indexPath.section == 0 && indexPath.row == 0) {
static NSString *SomeIdentifierA = #"SomeIdentifierA";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierA];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierA] autorelease];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text =cellValue;
return cell;
}
else if (indexPath.section ==1 && indexPath.row ==0) {
static NSString *SomeIdentifierB = #"SomeIdentifierB";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierB];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierB] autorelease];
[syncSwitch addTarget:self action:#selector(syncAtStartup:) forControlEvents:UIControlEventValueChanged];
//[cell.contentView addSubview:syncSwitch];
cell.accessoryView = syncSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.reuseIdentifier = #"Cell1";
}
cell.textLabel.text =#"Sync at Startup";
return cell;
}
else if(indexPath.section == 1 && indexPath.row == 1){
static NSString *SomeIdentifierC = #"SomeIdentifierC";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierC];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierC] autorelease];
[readSwitch addTarget:self action:#selector(confirmMarkAsRead:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = readSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =#"Confirm Mark as Read";
return cell;
}
else if(indexPath.section == 1 && indexPath.row == 2){
static NSString *SomeIdentifierD = #"SomeIdentifierD";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierD];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierD] autorelease];
[landscapeSwitch addTarget:self action:#selector(landscapeMode:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = landscapeSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =#"Landscape Mode";
return cell;
}
else if (indexPath.section == 1 && indexPath.row == 3) {
static NSString *SomeIdentifierE = #"SomeIdentifierE";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierE];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierE] autorelease];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text =#"Cache Settings";
return cell;
}
else if (indexPath.section == 1 && indexPath.row == 4) {
static NSString *SomeIdentifierJ = #"SomeIdentifierJ";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierJ];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierJ] autorelease];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text =#"Caches";
return cell;
}
else if(indexPath.section == 2 && indexPath.row == 0){
static NSString *SomeIdentifierN = #"SomeIdentifierF";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierN];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierN] autorelease];
[newItemsFirstSwitch addTarget:self action:#selector(newItemFirst:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = newItemsFirstSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =#"App Icon Badge";
return cell;
}
else if(indexPath.section == 2 && indexPath.row == 1){
static NSString *SomeIdentifierF = #"SomeIdentifierF";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierF];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierF] autorelease];
[badgeSwitch addTarget:self action:#selector(appBadgeSetting:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = badgeSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =#"App Icon Badge";
return cell;
}
else if(indexPath.section == 2 && indexPath.row == 2){
static NSString *SomeIdentifierG = #"SomeIdentifierG";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierG];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierG] autorelease];
[largeFontSwitch addTarget:self action:#selector (largeFontSetting:) forControlEvents:UIControlEventValueChanged];
//[largeFontSwitch addTarget:self action:#selector(largeFontSetting:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = largeFontSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text =#"Large Font Size";
return cell;
}
else if (indexPath.section == 3 && indexPath.row == 0) {
static NSString *SomeIdentifierH = #"SomeIdentifierH";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierH];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierH] autorelease];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text =#"Customize Sharing Options";
return cell;
}
else if (indexPath.section == 4 && indexPath.row == 0) {
static NSString *SomeIdentifierI = #"SomeIdentifierI";
// This could be some custom table cell class if appropriate
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SomeIdentifierI];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierI] autorelease];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text =#"Advanced Options";
return cell;
}
//switcher.on = [[NSUserDefaults standardUserDefaults]boolForKey:#"Settings"];
cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section ==0){
if (alreadySignedIn == NO) {
if(indexPath.section == 0 && ivControllerCell == nil ){
[tableView reloadData];
ivControllerCell = [[GoogleClientLogin alloc] initWithNibName:#"GoogleClientLogin" bundle:[NSBundle mainBundle]];
ivControllerCell.ViewPushed = YES;
//Push the view controller to the top of the stack.
[self.navigationController pushViewController:ivControllerCell animated:YES];
[ivControllerCell release];
ivControllerCell = nil;
}
}
if (alreadySignedIn ==YES) {
NSError *keyChainEmpty;
[SFHFKeychainUtils deleteItemForUsername:#"Username" andServiceName:#"iReader" error:&keyChainEmpty];
[SFHFKeychainUtils deleteItemForUsername:#"Password" andServiceName:#"iReader" error:&keyChainEmpty];
ivControllerCell = [[GoogleClientLogin alloc] initWithNibName:#"GoogleClientLogin" bundle:[NSBundle mainBundle]];
ivControllerCell.ViewPushed = YES;
[self.navigationController pushViewController:ivControllerCell animated:YES];
}
}
}
-(void) removeSelfFromWindow
{/*
if(self.view.superview){
[UIView beginAnimations:#"curldown" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:NO];
[self.view.superview removeFromSuperview];
}
[UIView commitAnimations];
*/}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
/*static Settings * _standardSettings = nil;
+(Settings *)standardSettings
{
if (_standardSettings == nil)
_standardSettings = [[Settings alloc] init];
return _standardSettings;
}*/
-(void) setUIElements {
[landscapeSwitch setOn:[self landscapeModeSwitch]];
//[feedList setSelectedFeeds:[self taglist]];
}
- (void)dealloc {
[self save];
[plistData release];
[plistName release];
[super dealloc];
}
#end
I am getting the following error when I start scrolling the table view.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType addTarget:action:forControlEvents:]: unrecognized selector sent to instance 0x5f463e0'
Can somebody please help me with this error?
Cheers
Don't autorelease the switches when you alloc them. After those lines you don't own any of those objects.
syncSwitch=[[UISwitch alloc] initWithFrame:CGRectZero];
Release them in the dealloc method
[syncSwitch release];

Resources