How to insert an value into a NSMutableArray? [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I know that my question sounds stupid, but it doesn't work with my code:
#import "TermineViewController.h"
#import "DetailViewController.h"
#interface TermineViewController ()
#end
#implementation TermineViewController {
NSArray *tableData;
int i;
NSString *userid;
NSString *selection;
NSMutableArray *userids;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [[NSURL alloc] initWithString: #"http://example.com"];
NSString *dataString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
tableData = [dataString componentsSeparatedByString:#"--"];
NSLog(userids);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return ([tableData count])/4;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.contentView.backgroundColor = [UIColor blackColor];
cell.accessoryView.backgroundColor = [UIColor blackColor];
[self.tableView setSeparatorColor:[UIColor whiteColor]];
self.view.backgroundColor = [UIColor blackColor];
//Declare all Labels
UILabel *name = (UILabel *)[cell viewWithTag:100];
UILabel *service = (UILabel *)[cell viewWithTag:200];
UILabel *time = (UILabel *)[cell viewWithTag:300];
//Write into Labels and add one to int i (declared in implementation)
name.text = [tableData objectAtIndex:i];
i++;
service.text = [tableData objectAtIndex:i];
i++;
time.text = [tableData objectAtIndex:i];
i++;
userid = [tableData objectAtIndex:i];
NSString *usrid = [NSString stringWithFormat:#"%#", userid];
[userids addObject:usrid];
i++;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selection = userids[indexPath.row];
NSLog(#"User selected %#", selection);
NSLog(userids[0]);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"details"]) {
DetailViewController *destViewController = (DetailViewController *)[segue destinationViewController];
destViewController.userid = selection;
}
}
#end
So, here are two issues: the first is that I don't get any values in my NSMutableArray (btw it is declared in the #implementation). The second is that I get following error message if the user scrolls in the TableView:
Terminating app due to uncaught exception 'NSRangeException', reason:
'* -[__NSArrayM objectAtIndex:]: index 20 beyond bounds [0 .. 19]'
* First throw call stack: [...]
I don't know whats the matter? Yes, in my Array are 20 values, but the 20th exists!
Thank you very much!!!!
Greetings, Kitzng

You're not creating the array anywhere, you have to do userids = [[NSMutableArray alloc] init] before you can use it.

In your code, i is not defined. My guess is that you mean indexPath.row or indexPath.section. If there are no values in your array, the issue may be that you haven't initialized it when you start adding the objects, and then call something like
tableData = [[NSMutableArray alloc] initWithCapacity:20]
but that's purely speculation based off of the details provided.
As far as the tableView scroll issue, if your array contains 20 objects, indexes [0...19] are the objects. If the table view, in numberOfRowsInSection: is returning something like tableData.count + 1, there will be not data at the index for the last row.

Related

[__NSArrayI objectAtIndex:]: message sent to deallocated instance 0x7fbdae1a2080

In tableView I have a few objects that are showing up just fine. However when I interact with the list and scroll down (forward) the app will crash. I have never seen this before and am not aware of why this is happening. I am using a 3rd party calendar in combination with my code, I figured I should mention this but I do not see this being the main issue.
#import "VRGViewController.h"
#interface VRGViewController ()
#end
#implementation VRGViewController{
NSArray *calendarTableData;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
VRGCalendarView *calendar = [[VRGCalendarView alloc] init];
calendar.delegate=self;
calendar.center = self.view.center;
[self.view addSubview:calendar];
calendarTableData = [NSArray arrayWithObjects:#"Egg Benedict", #"Mushroom Risotto",nil];
}
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated {
if (month==[[NSDate date] month]) {
NSArray *dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:5], nil];
[calendarView markDates:dates];
}
}
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date {
NSLog(#"Selected date = %#",date);
}
#pragma mark - User Defined Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [calendarTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = #"Services";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [calendarTableData objectAtIndex:indexPath.row];
return cell;
}
#end
You have to declare your datasource the following way:
calendarTableData = [[NSArray alloc]initWithObjects:#"Egg Benedict",
#"Mushroom Risotto",nil];
The issue was coming from how I was calling my array.
Since I was using 3rd party code I had disable ARC. Which was causing my issue with how I was calling my array of objects. Thank you to #meda for helping provide me with the answer - after I implemented it I then realized where I was wrong

Populating a UITableView within a UIViewController and changing data source with UISegmentedControl

I am trying to populate a UITableView that I put inside a UIViewController, underneath a UISegmentedControl, which is depicted in the picture:
Upon pressing any of the segments, I want the UITableView to be repopulated with a different set of data. Here is my relevant code:
#interface OTValuesViewController ()
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property (weak, nonatomic) IBOutlet UISegmentedControl *segmentControl;
#end
#implementation OTValuesViewController
- (IBAction)segmentValueChanged:(id)sender {
UISegmentedControl *segment = self.segmentControl;
UINavigationItem *navItem = self.navigationItem;
UIBarButtonItem *addButton = navItem.rightBarButtonItem;
switch (segment.selectedSegmentIndex) {
case 0:
addButton.action = #selector(addNewVision:);
[self.tableView reloadData];
break;
case 1:
addButton.action = #selector(addNewPurpose:);
[self.tableView reloadData];
break;
case 2:
addButton.action = #selector(addNewPlan:);
[self.tableView reloadData];
break;
default:
[self.tableView reloadData];
break;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UISegmentedControl *segment = self.segmentControl;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"OTValuesTableViewCell" forIndexPath:indexPath];
NSArray *visions = [[OTVisionStore sharedStore] allVisions];
NSArray *purposes = [[OTPurposeStore sharedStore] allPurposes];
NSArray *plans = [[OTPlanStore sharedStore]allPlans];
OTVision *vision = [visions objectAtIndex:indexPath.row];
OTVision *purpose = [purposes objectAtIndex:indexPath.row];
OTVision *plan = [plans objectAtIndex:indexPath.row];
NSString *textLabel = [vision description];
if (segment.selectedSegmentIndex==0) {
textLabel = [vision description];
cell.textLabel.text = textLabel;
}
else if (segment.selectedSegmentIndex==1) {
textLabel = [purpose description];
cell.textLabel.text = textLabel;
}
else{
textLabel = [plan description];
cell.textLabel.text = textLabel;
}
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
UISegmentedControl *segment = self.segmentControl;
if(segment.selectedSegmentIndex==0) {
return [[[OTVisionStore sharedStore]allVisions]count];
}
else if (segment.selectedSegmentIndex==1) {
return [[[OTPurposeStore sharedStore]allPurposes]count];
}
else{
return [[[OTPlanStore sharedStore]allPlans]count];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.title=#"Mission Statement";
UINavigationItem *navItem = self.navigationItem;
UIBarButtonItem *rbbi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(addNewVision:)];
navItem.rightBarButtonItem = rbbi;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
My issue is: when I build and run the project, everything is fine -- the cells are populated in my default tab (vision). When I click a UISegmentedControl button, I get the error:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
If I remove:
self.tableView.dataSource = self;
self.tableView.delegate = self;
from my viewDidLoad, this error does not occur (though, the UITableView obviously doesn't get populated.) This leads me to believe that the error is derived from my populating the cells based on the UISegmentedController's selected segment, however, I do not know what is specifically causing it.
Any help would be greatly appreciated!
The problem is in your cellForRowAtIndexPath method. You try to use the current index path for all of your arrays, not just the applicable array. Try something like this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UISegmentedControl *segment = self.segmentControl;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"OTValuesTableViewCell" forIndexPath:indexPath];
if (segment.selectedSegmentIndex==0) {
NSArray *visions = [[OTVisionStore sharedStore] allVisions];
OTVision *vision = [visions objectAtIndex:indexPath.row];
NSString *textLabel = [vision description];
cell.textLabel.text = textLabel;
}
else if (segment.selectedSegmentIndex==1) {
NSArray *purposes = [[OTPurposeStore sharedStore] allPurposes];
OTVision *purpose = [purposes objectAtIndex:indexPath.row];
NSString *textLabel = [purpose description];
cell.textLabel.text = textLabel;
}
else{
NSArray *plans = [[OTPlanStore sharedStore]allPlans];
OTVision *plan = [plans objectAtIndex:indexPath.row];
NSString *textLabel = [plan description];
cell.textLabel.text = textLabel;
}
return cell;
}

Using Sections in TableView

How do you pass data from a tableview Controller with sections to a ViewController? I can do it when I'm not using sections, but the program crashes when I use sections? And I don't understand.
This is the error message I get and it cranes with a SIGABIT message on this line:
NSString *mytempName = [NSString stringWithString:[tempObject charName]];
Error message:
2014-07-24 06:38:05.465 Passing_Data_With_Two_Sections[469:60b] -[__NSArrayM charName]: unrecognized selector sent to instance 0x8f0d230
2014-07-24 06:38:05.501 Passing_Data_With_Two_Sections[469:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM charName]: unrecognized selector sent to instance 0x8f0d230'
Here is the code from the TableView Controller
#import "myTableView.h"
#interface myTableView ()
#end
#implementation myTableView
NSMutableArray *myHeadersArray;
NSMutableArray *myFightersArray;
NSMutableArray *myLadiesArray;
NSMutableArray *myArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
myHeadersArray = [[NSMutableArray alloc]initWithObjects:#"Fighters", #"Ladies", nil];
myFightersArray = [[NSMutableArray alloc]init];
myLadiesArray = [[NSMutableArray alloc]init];
objectFile *myObject = [[objectFile alloc]init];
myObject.charName = #"Peter Pan";
[myFightersArray addObject:myObject];
myObject = [[objectFile alloc]init];
myObject.charName = #"Mikey Mouse";
[myFightersArray addObject:myObject];
myObject = [[objectFile alloc]init];
myObject.charName = #"Mrs Duck";
[myLadiesArray addObject:myObject];
myObject = [[objectFile alloc]init];
myObject.charName = #"Mini Mouse";
[myLadiesArray addObject:myObject];
myArray = [NSMutableArray arrayWithObjects:myFightersArray, myLadiesArray, nil];
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [myHeadersArray objectAtIndex:section];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [myHeadersArray count];
//This seems to crash if you go above 2. Which I assume is somehow tied in with the sections.
//Adding additional names now no longer crash. But if I changed it to myArray then it crashes
//bitching it being greater 2.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"myCell" forIndexPath:indexPath];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = ((myTempObjectFile*)[[myArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]).charName;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController *vc = [segue destinationViewController];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
int myrow = [path row];
myTempObjectFile *tv = [myArray objectAtIndex:myrow];
vc.tempObject = tv;
}
#end
And here is the code from my ViewController:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize myLabelOutput;
#synthesize tempObject;
- (void)viewDidLoad
{
NSString *mytempName = [NSString stringWithString:[tempObject charName]];
[myLabelOutput setText:mytempName];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
This happens because you try to invoke method charName for an array.
As I see you store arrays in array and you should change implementation to:
myTempObjectFile *tv = [[myArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]
vc.tempObject = tv;
or just
myTempObjectFile *tv = myArray[indexPath.section][indexPath.row]
vc.tempObject = tv;
This answer to your question.
But I think that here we need to refactor: not very beautiful to store arrays in an array, it is better to make an abstract object for this data structure. And tempObject name does not bear any semantic meaning.

How can I display multiple parameters of the same key from a .plist File on Objective-c?

I have this arquivo.plist below.
I looked at Apple's documentation, but I could not find how to make the listing look and I hope someone can help me.
In the first UITableView, I make a list of names present in arquivo.plist using the following code and loading the following method below.
What I'm trying to do is: When the user clicks on a tableView name, he is taken to a second screen with a new tableView that will display the "frams" of that user.
The problem is that the code I'm using to select the "frams" is the same code that I am using for listing the names on the first screen, but it is not working, because each user has only one name, but it has several "frams".
When I try to implement this, I can even assemble the array with the "frams" and pass using segue (i'll show the array with an NSLog), but this array can not be displayed as a tableView for an error that Xcode is giving me:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]:
unrecognized selector sent to instance 0x8b87a60'
The code from the fist view (ViewController.m) is below the contatos.plist
I hope you understand what I'm trying to do and bring me a light!
Thank you all!
a screenshot of the .plist file is bellow:
http://img268.imageshack.us/img268/7356/jl26.png
For reference and for you to better understand the issue, when the user clicks on a table name, an array is generated with "frams" this patient (patients have on average 3 frams each). The Array NSLog that it should be passed to the other page and comport a new table generates the following text:
12/12/2013 16:10:13.513 rer [24251:70 b] (
{
1 = 11;
2 = 12;
3 = 13;
}
I think that's where the problem lies, because this method of Array can not be implemented in a TableView, so I look a light of a better way to mount this array and select frams when I click a patient
So here is my ViewController.m:
#import "ViewController.h"
#import "Contato.h"
#import "perfilViewController.h"
#interface ViewController ()
-(void) loadContacts;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadContacts];
}
-(void) loadContacts
{
NSString *plistCaminho = [[NSBundle mainBundle] pathForResource:#"contatos"
ofType:#"plist"];
NSDictionary *pl = [NSDictionary dictionaryWithContentsOfFile:plistCaminho];
NSArray *dados = [pl valueForKey:#"contatos"];
contatos = [[NSMutableArray alloc] init];
for (NSDictionary *item in dados) {
NSString *nome = [item valueForKey:#"nome"];
NSString *telefone = [item valueForKey:#"telefone"];
NSString *fram = [item valueForKey:#"fram"];
Contato *c = [[Contato alloc] initWithNome:nome andTelefone:telefone andFram:fram];
[contatos addObject:c];
}
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return contatos.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CelulaContatoCacheID = #"CelulaContatoCacheID";
UITableViewCell *cell = [self.tabelaContatos dequeueReusableCellWithIdentifier:CelulaContatoCacheID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CelulaContatoCacheID];
}
Contato *contato = [contatos objectAtIndex:indexPath.row];
cell.textLabel.text = contato.nome;
return cell;
}
#pragma mark -
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Contato *contato = [contatos objectAtIndex:indexPath.row];
NSString *msg = [NSString stringWithFormat:#"Fram:%#",contato.fram];
fran = [[NSMutableArray alloc] init];
fran = [NSMutableArray arrayWithObject:contato.telefone];
NSLog(#"finalmente eu consegui essa porra!!!%#", fran);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Contato"
message:msg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[self.tabelaContatos deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"vai"]) {
NSIndexPath *indexPath = [self.tabelaContatos indexPathForSelectedRow];
perfilViewController *destViewController = segue.destinationViewController;
Contato *contato = [contatos objectAtIndex:indexPath.row];
fran = [[NSMutableArray alloc] init];
fran = [NSMutableArray arrayWithObject:contato.fram];
destViewController.frans = fran;
NSLog(#"%#%#", fran, destViewController.frans);
}
}
#end
I'd firstly do:
//declare NSDictionary *pl; in the ViewController.h
pl = [NSDictionary dictionaryWithContentsOfFile:plistCaminho];
Then to display Names, i'd simply use the dictionary as such:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[pl objectForKey:#"contatos"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//...
//following commented line not needed anymore
//Contato *contato = [contatos objectAtIndex:indexPath.row];
cell.textLabel.text = [[[pl objectForKey:#"contatos"]
objectAtIndex:indexPath.row]
objectForKey:#"nome"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//following commented line not needed anymore
//Contato *contato = [contatos objectAtIndex:indexPath.row];
//NOTE: fran is a dictionary now
//change "fran" declaration in the ViewController.h to
//NSDictionary *fran;
fran = [[NSDictionary alloc] init];
fran = [[pl objectForKey:#"contatos"]
objectAtIndex:indexPath.row];
NSLog(#"finalmente eu consegui essa porra!!!%#", fran);
//...
//don't deselectRow (the indexPathForSelectedRow will not work correctly later)
//[self.tabelaContatos deselectRowAtIndexPath:indexPath animated:YES];
}
then on -prepareForSegue i'd pass the dictionary associated with the selected row:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"vai"]) {
NSIndexPath *indexPath = [self.tabelaContatos indexPathForSelectedRow];
perfilViewController *destViewController = segue.destinationViewController;
//following commented line not needed anymore
//Contato *contato = [contatos objectAtIndex:indexPath.row];
//NOTE: fran is a dictionary now
//change "fran" declaration in the ViewController.h to
//NSDictionary *fran;
fran = [[NSDictionary alloc] init];
fran = [[[pl objectForKey:#"contatos"]
objectAtIndex:indexPath.row]
objectForKey:#"fram"];
//NOTE: destViewController.frans should be a dictionary
//handle it appropriately
destViewController.frans = fran;
}
}
so basically, all dictionary use, no need for Contato *contato at all.
EDIT: As for your current method, you would be better off replicating the same structure.
As in:
[array of names] has {dictionary with user details} having a key that has {dictionary of frams}
I'd recommend you not using a dictionary to store your Fram values, use an array instead.
This way, you can get the Fram values like this:
for (NSDictionary *item in dados) {
NSString *nome = [item valueForKey:#"nome"];
NSString *telefone = [item valueForKey:#"telefone"];
NSArray *fram = [item valueForKey:#"fram"];
Contato *c = [[Contato alloc] initWithNome:nome andTelefone:telefone andFram:[fram objectAtIndex:index]];
[contatos addObject:c];
}
Where index is an integer variable you'll have to work out how to handle.
PS: be a little more polite when logging you app ;)

Throwing thread 1 signal SIGABRT while trying to implement PARSE PFQueryTableViewController

It doesn't matter what I try I cant seem to even get past changing UITableView with the PFQueryTableViewController. I have added code, gone back through code, got rid of code and it all seems to throw the same error pretty much after changing from UITableView
i get
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:'-[UITableViewController loadView] loaded the "2-view-3" nib but didn't get a UITableView.'
i'm just trying to populate a table from PARSE, basic stuff but i'm just trying to help my younger brother with my limited capabilities. Any help would be much appreciated
here's some code. i've linked to parse in my appdelegate, all that's fine. ive tested that.
ViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#interface BaliPartyViewController : PFQueryTableViewController
#end
ViewController.m
#import "BaliPartyViewController.h"
#import "PartyDetailViewController.h"
#import "CustomCell.h"
#interface BaliPartyViewController ()
#end
#implementation BaliPartyViewController {
}
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
// The className to query on
self.parseClassName = #"Recipe";
// The key of the PFObject to display in the label of the default cell style
self.textKey = #"name";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = NO;
}
return self;
}
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = #"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// Configure the cell
PFFile *thumbnail = [object objectForKey:#"imageFile"];
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.image = [UIImage imageNamed:#"placeholder.jpg"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];
UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
nameLabel.text = [object objectForKey:#"name"];
UILabel *prepTimeLabel = (UILabel*) [cell viewWithTag:102];
prepTimeLabel.text = [object objectForKey:#"prepTime"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
[self performSegueWithIdentifier: #"showPartyDetail" sender: self];
}
}
/*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showPartyDetail"]) {
PartyDetailViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = nil;
if ([self.searchDisplayController isActive]) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
destViewController.partyName = [searchResults objectAtIndex:indexPath.row];
destViewController.partyDate = [searchResults objectAtIndex:indexPath.row];
destViewController.information = [searchResults objectAtIndex:indexPath.row];
destViewController.location = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
destViewController.partyName = [parties objectAtIndex:indexPath.row];
destViewController.partyDate = [partyTime objectAtIndex:indexPath.row];
destViewController.information = [information objectAtIndex:indexPath.row];
destViewController.location = [location objectAtIndex:indexPath.row];
destViewController.photo = [detailPicture objectAtIndex:indexPath.row];
}
// Hide bottom tab bar in the detail view
destViewController.hidesBottomBarWhenPushed = YES;
}
}*/
#end

Resources