UITableView isn't working - objective-c

Im trying to make a comments UITableView inside a UIViewController but I'm having problems. If I set the text directly, it shows up (cell.username.text) but if I try to fill it with a PFQuery (parse.com) nothing shows up
//DetailViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#interface DetailViewController : UIViewController{
}
#property (strong, nonatomic) PFObject *place;
#property (strong, nonatomic) IBOutlet PFImageView *userPhoto;
#property (strong, nonatomic) IBOutlet UILabel *username;
#property (strong, nonatomic) IBOutlet UILabel *message;
#property (strong, nonatomic) IBOutlet UILabel *distance;
#property (strong, nonatomic) IBOutlet UILabel *checkCount;
#property (strong, nonatomic) IBOutlet PFImageView *photo;
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#property (strong, nonatomic) IBOutlet UITableView *commentsTableView;
- (IBAction)checkMarkButton:(UIButton *)sender;
#end
//DetailViewController.m
#import "DetailViewController.h"
#import "CommentsViewController.h"
#interface DetailViewController (){
CommentsViewController *test;
}
#end
#implementation DetailViewController
#synthesize place;
#synthesize userPhoto, message, username, checkCount, photo, scroller, commentsTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
test = [[CommentsViewController alloc] init];
self.commentsTableView.delegate = test;
self.commentsTableView.dataSource = test;
[test commentsQuery:place];
}
//CommentsViewController.h
#import <Parse/Parse.h>
#interface CommentsViewController : UITableViewController{
}
#property (strong, nonatomic) PFObject *place;
- (void)commentsQuery:(PFObject *)object;
#end
//CommentsViewController.m
#import "CommentsViewController.h"
#import "DetailViewController.h"
#import "CommentsCell.h"
#interface CommentsViewController (){
NSArray *commentsArray;
}
#end
#implementation CommentsViewController
#synthesize place;
- (void)commentsQuery:(PFObject *)object {
place = object;
PFQuery *query1 = [PFQuery queryWithClassName:#"activity"];
[query1 whereKey:#"type" equalTo:#"comment"];
[query1 whereKey:#"place" equalTo:place];
[query1 orderByDescending:#"createdAt"];
[query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
commentsArray = [[NSArray alloc]initWithArray:objects];
NSLog(#"%lu", (unsigned long)[commentsArray count]);
}
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [commentsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = #"Cell";
CommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CommentsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PFObject *tempObj = [commentsArray objectAtIndex:indexPath.row];
cell.username.text = #"username";
cell.comment.text = [tempObj objectForKey:#"content"];
cell.userThumbnail.file = [tempObj objectForKey:#"userThumbnail"];
[cell.userThumbnail loadInBackground];
return cell;
}
#end

My problem was calling reloadData. I followed the answer here and it works UITableView delegate and datasource in a separate class after parsing

Related

table view no data showing in the table cell

I have face problem in that code when i have run that code then no data show in tableview on it's table cell. there is no error in console but data not show. please Guide me what's the mistake i have do that code.
InvoiceCell.h
#import <UIKit/UIKit.h>
#interface InvoiceCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UIImageView *ItemImage;
#property (strong, nonatomic) IBOutlet UILabel *ItemName;
#property (strong, nonatomic) IBOutlet UILabel *ItemType;
#property (strong, nonatomic) IBOutlet UILabel *date;
#property (strong, nonatomic) IBOutlet UILabel *Amount;
#property (strong, nonatomic) IBOutlet UILabel *status;
#end
InvoiceCell.m
#import "InvoiceCell.h"
#implementation InvoiceCell
#synthesize ItemImage,ItemName,ItemType,Amount,status;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
InvoiceViewController.h
#import <UIKit/UIKit.h>
#interface InvoiceViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (nonatomic,strong) NSArray *DataImages;
#property (nonatomic, strong) NSArray *DataName;
#property (nonatomic, strong) NSArray *Datatype;
#property (nonatomic, strong) NSArray *DataAmount;
#property (nonatomic, strong) NSArray *DataStatus;
#property (nonatomic, strong) NSArray *Datadate;
#end
InvoiceViewController.m
#import "InvoiceViewController.h"
#import "InvoiceCell.h"
#interface InvoiceViewController ()
#end
#implementation InvoiceViewController
#synthesize DataImages,DataName,Datatype,DataAmount,DataStatus,Datadate;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
DataImages = #[#"img1.jpg", #"img2.jpg", #"img3.jpg", #"img4.jpg", #"img5.jpg"];
DataName = #[#"Suit", #"Shirt", #"paint", #"Suit", #"Suit"];
Datatype = #[#"Brown", #"Black", #"Blue", #"Black", #"Blue"];
DataAmount = #[#"$500", #"$400",#"$500", #"$400",#"$300"];
DataStatus = #[#"Paid", #"Due", #"Paid", #"Due", #"Paid"];
Datadate = #[#"8/5/2014", #"10/6/2014",#"8/5/2014", #"10/6/2014",#"8/5/2014"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return DataName.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"InvoiceCell";
InvoiceCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
{
cell = [[InvoiceCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
long row = [indexPath row];
NSLog(#"%#", cell.ItemName.text = DataName[row]);
cell.ItemName.text = DataName[row];
cell.ItemType.text = Datatype[row];
cell.ItemImage.image = [UIImage imageNamed:DataImages[row]];
cell.date.text = Datadate[row];
cell.Amount.text = DataAmount[row];
cell.status.text = DataStatus[row];
return cell;
}
In the Debug Window and console Data show but not show data on simulator screen in the tableview cells
Thank you.
You may have a tableView in your StoryBoard, but you have no connection to it in your code. Add this to your InvoiceViewController.h
#property IBOutlet UITableView *tableView;
and hook it up to your TableView in Interface Builder.
Then you can set the DataSource and Delegate in your InvoiceViewController.m -[viewDidLoad] method
_tableView.delegate = self;
_tableView.dataSource = self;
Now the TableView will know to call the delegate methods you implemented and you should see your data in the table.

Content Not Moving Between Classes?

I am writing an app that is transferring data from one class to another. For some reason the text is not being displayed on the other view when it is supposed to.
My code:
.h Master class:
#import <UIKit/UIKit.h>
#class SSWSettings;
#interface SSWSelectProgram : UITableViewController
#property (strong, nonatomic) SSWSettings *detailViewController;
#property (weak, nonatomic) IBOutlet UILabel *p1;
#end
.m master class:
#import "SSWSelectProgram.h"
#import "SSWSettings.h"
#interface SSWSelectProgram ()
#end
#implementation SSWSelectProgram
#synthesize p1;
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cellChosen = [self.tableView cellForRowAtIndexPath:indexPath];
if (cellChosen == static1) {
self.detailViewController.detailItem = p1.text;
[self dismissViewControllerAnimated:YES completion:NULL];
}
.h detail class
#import <UIKit/UIKit.h>
#interface SSWSettings : UITableViewController <UITableViewDelegate, UITableViewDataSource>
#property (strong, nonatomic) id detailItem;
#property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#end
.m detail class
#import "SSWSettings.h"
#import "SSWSelectProgram.h"
#interface SSWSettings ()
-(void)configureView;
#end
#implementation SSWSettings
#synthesize detailDescriptionLabel;
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[self configureView];
}
Your object "detailItem" is of type id.
Thus, it does not inherit from NSObject and the
[self.detailItem description];
call Will not return anything.
Try
self.detailDescriptionLabel.text = (NSString*) self.detailItem;
A better solution, of course, is to not use the type 'id' and use NSString

UITableView in a UIViewController on an iPad

I'm trying to develop a tiny app to manage the registry for a teacher. My app works so:
I present a UIViewController (only landscape) to select the class.
When I press the button (for example: 1F), I call a method to parse an XML file in which I got the name and the surname of the students. So I put this name and surname into an NSArray of NSDictionary (arrayStudents[0] = dictStudents and dictStudents is composed by 3 key: number, name and surname).
In the second UIViewController I put a UITableView on the left of the screen and a normal view to the right. In the UITableView I want to have the name and surname of the students and on the right I want to show the score about test of the student selected by tapping on the UITableView.
This is how my viewController looks like:
My problem is how to populate the UITableView. I connected the tableView with an IBOutlet to my second viewController and then I connect the delegate and the dataSource to the second viewController, but the app is still crashing. I will post here the code of my table view class and second view controller, so you can help me to fix this problem.
Here you can see the connection tab of my tableView:
tableView.h
#import <UIKit/UIKit.h>
#interface tableView : UITableView <UITableViewDelegate,UITableViewDataSource>
#property (nonatomic, strong) NSMutableArray *arrayStudents;
#end
tableView.m
#import "tableView.h"
#implementation tableView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrayStudents.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.arrayStudents[indexPath.row] objectForKey:#"name"];
cell.detailTextLabel.text = [self.arrayStudents[indexPath.row] objectForKey:#"surname"];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
#end
detailsViewController.h
#import <UIKit/UIKit.h>
#interface DetailsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (weak, nonatomic) IBOutlet UITableView *tableViewStudentsNameAndSurname;
#property (weak, nonatomic) IBOutlet UIView *viewDetails;
#property (weak, nonatomic) IBOutlet UILabel *labelName;
#property (weak, nonatomic) IBOutlet UILabel *labelSurname;
#property (weak, nonatomic) IBOutlet UITextField *textFieldTest1;
#property (weak, nonatomic) IBOutlet UITextField *textFieldTest2;
#property (weak, nonatomic) IBOutlet UITextField *textFieldTest3;
#property (weak, nonatomic) IBOutlet UITextField *textFieldText4;
#property (weak, nonatomic) IBOutlet UITextView *textViewValutation;
#property (weak, nonatomic) IBOutlet UILabel *labelTotalScore;
#property (nonatomic, strong) NSString *fileName;
- (IBAction)saveDataToPlistFile:(id)sender;
#end
detailsViewController.m
#import "DetailsViewController.h"
#import "ParserXML.h"
#import "tableView.h"
#interface DetailsViewController () {
ParserXML *parser;
tableView *table;
}
#end
#implementation DetailsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
parser = [[ParserXML alloc] init];
NSLog(#"DetailsViewController: %#", self.fileName);
parser.fileName = self.fileName;
[parser parseXML];
table = [[tableView alloc] init];
table.arrayStudents = [parser.arrayStudents mutableCopy];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)saveDataToPlistFile:(id)sender {
}
#end
ParserXML.h
#import <Foundation/Foundation.h>
#interface ParserXML : NSObject <NSXMLParserDelegate>
#property (nonatomic, strong) NSMutableArray *arrayStudents;
#property (nonatomic, strong) NSDictionary *dictStudents;
#property (nonatomic, strong) NSString *fileName;
- (void) parseXML;
#end
ParserXML.m
#import "ParserXML.h"
#interface ParserXML() {
NSXMLParser *nameStudentParser;
NSString *pathXmlFile;
}
#end
#implementation ParserXML
- (id) init {
self = [super init];
if (self) {
self.arrayStudents = [[NSMutableArray alloc] init];
pathXmlFile = [[NSBundle mainBundle] pathForResource:self.fileName ofType:#"xml"];
}
return self;
}
- (void) parseXML {
NSURL *xmlUrl = [NSURL URLWithString:pathXmlFile];
NSString *host = [xmlUrl host];
if (xmlUrl == nil || host == nil) {
NSData *data = [[NSData alloc] initWithContentsOfFile:pathXmlFile];
nameStudentParser = [[NSXMLParser alloc] initWithData:data];
} else {
nameStudentParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlUrl];
}
[nameStudentParser setDelegate:self];
[nameStudentParser setShouldProcessNamespaces:NO];
[nameStudentParser setShouldReportNamespacePrefixes:NO];
[nameStudentParser setShouldResolveExternalEntities:NO];
[nameStudentParser parse];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
NSLog(#"File trovato inizio il parsing del documento");
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(#"Errore Parsing");
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:#"students"]) {
} else if ([elementName isEqualToString:#"student"]) {
NSString *numberValue = attributeDict[#"number"];
NSString *nameValue = attributeDict[#"name"];
NSString *surnameValue = attributeDict[#"surname"];
//Inserire dizionario di array
self.dictStudents = #{#"number": numberValue,
#"name": nameValue,
#"surname" : surnameValue};
[self.arrayStudents addObject:self.dictStudents];
NSLog(#"arrayStudents dim = %d", self.arrayStudents.count);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(#"ArrayFuels = %#", self.arrayStudents);
}
#end
When I run the app Xcode says:
[DetailsViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x751da40
Can you help me to fix that problem? What I'm doing wrong?
Okay, So I'm pretty new to objective C so this is not an expert opinion. But from what I get, it is looking for the delegate method that should be there in DetailsViewController class. You have connected your table view delegate/datasource to DetailsViewController class, I think you're supposed to specify the class as being the delegate class of UITableView as well.
In DetailsViewController.h:
#interface DetailsViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
and then plug in the UITableView Delegate methods in DetailsViewController.m file.
Although, what I don't get is why are you using 2 table view classes? If you want to use tableView class, why not initialize in DetailsViewController::viewDidLoad and simply:
[self.view addSubView:tableView]
I don't think there is a need for tableViewStudentsNameAndSurname in your class.

Passing map-data between ViewController

I nearly followed this post. The viewcontroller will push via storyboard. Here the relevant code:
ViewController.m:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
MapPoint.h:
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_title;
NSString *_subtitle;
CLLocationCoordinate2D _coordinate;
UIImage *_storeImage;
}
#property (copy) NSString *title;
#property (copy) NSString *subtitle;
#property (nonatomic, readonly) UIImage *storeImage;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle coordinate:(CLLocationCoordinate2D)coordinate storeImage:(UIImage*)storeImage;
and DetailViewController:
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
I think my mistake is in the calloutAccessoryControlTapped method but I dont know what is the real reason for this issue.
If you use a storyboard, can use prepareForSegue method and set within a class similarly as you have made.
I post a portion of code
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"Brs"]){
NSLog(#"segue %# ",[segue identifier]);
[segue.destinationViewController setPath:[ris_xml objectAtIndex:index_post-1] ];
}
}
In this example I set attribute "Path" of next UIViewController only if his identifier is "Brs".
For use this method is need set UIviewController identifier into storyboard right panel.
Using this isn't need to instantiate new UIViewController if you have it in storyboard.
I solved it by thinking about loading sequence.
All what to do is create temporary #properties
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
#property (nonatomic) NSString *titleTMP; //added
#property (nonatomic) NSString *subtitleTMP; //added
and do
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
The DetailViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
titleLabel.text = titleTMP;
textView.text = subtitleTMP;
}

XCode 4.2: Semantic Issue '#end' is missing in implementation context & Unexpected '#' in program

I am new to XCODE, but I am trying to learn. Basically my project is a rework of Nada Jaksic's Creating a table-based form on the iPhone". I would appreciate being informed where I went wrong in my coding, so that I can learn from my mistakes. Any and all help is definitely appreciated!
From the SignupTableViewController.h file:
#import <UIKit/UIKit.h>
#interface SignupTableViewController : UITableViewController<UITextFieldDelegate, UIActionSheetDelegate>
{
IBOutlet UITableViewCell *cellExaminername;
IBOutlet UITableViewCell *cellExamineraddress;
IBOutlet UITableViewCell *cellExaminercity;
IBOutlet UITableViewCell *cellExaminerstate;
IBOutlet UITableViewCell *cellExaminerzip;
IBOutlet UITableViewCell *cellExamineremail;
IBOutlet UITableViewCell *cellSearchthroughdate;
IBOutlet UITableViewCell *cellTitleheldby;
IBOutlet UITableViewCell *cellPropertyaddress1;
IBOutlet UITableViewCell *cellPropertyaddress2;
IBOutlet UITableViewCell *cellPropertycity;
IBOutlet UITableViewCell *cellPropertystate;
IBOutlet UITableViewCell *cellProperyzip;
IBOutlet UITableViewCell *cellTitlesearchnotes;
IBOutlet UITextField* txtExaminername;
IBOutlet UITextField* txtExamineraddress;
IBOutlet UITextField* txtExaminercity;
IBOutlet UITextField* txtExaminerstate;
IBOutlet UITextField* txtExaminerzip;
IBOutlet UITextField* txtExamineremail;
IBOutlet UITextField* txtSearchthroughdate;
IBOutlet UITextField* txtTitleheldby;
IBOutlet UITextField* txtPropertyaddress1;
IBOutlet UITextField* txtPropertyaddress2;
IBOutlet UITextField* txtPropertycity;
IBOutlet UITextField* txtPropertystate;
IBOutlet UITextField* txtPropertyzip;
IBOutlet UITextField* txtTitlesearchnotes;
UIActivityIndicatorView* activityIndicator;
}
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminername;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExamineraddress;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminercity;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminerstate;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminerzip;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellExamineremail;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellSearchthroughdate;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellTitleheldby;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertyaddress1;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertyaddress2;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertycity;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertystate;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellProperyzip;
#property (nonatomic, retain) IBOutlet UITableViewCell *cellTitlesearchnotes;
#property (nonatomic, retain) IBOutlet UITextField* txtExaminername;
#property (nonatomic, retain) IBOutlet UITextField* txtExamineraddress;
#property (nonatomic, retain) IBOutlet UITextField* txtExaminercity;
#property (nonatomic, retain) IBOutlet UITextField* txtExaminerstate;
#property (nonatomic, retain) IBOutlet UITextField* txtExaminerzip;
#property (nonatomic, retain) IBOutlet UITextField* txtExamineremail;
#property (nonatomic, retain) IBOutlet UITextField* txtSearchthroughdate;
#property (nonatomic, retain) IBOutlet UITextField* txtTitleheldby;
#property (nonatomic, retain) IBOutlet UITextField* txtPropertyaddress1;
#property (nonatomic, retain) IBOutlet UITextField* txtPropertyaddress2;
#property (nonatomic, retain) IBOutlet UITextField* txtPropertycity;
#property (nonatomic, retain) IBOutlet UITextField* txtPropertystate;
#property (nonatomic, retain) IBOutlet UITextField* txtPropertyzip;
#property (nonatomic, retain) IBOutlet UITextField* txtTitlesearchnotes;
-(void)signup;
#end
From my SignupTableViewController.m file:
#import "SignupTableViewController.h"
#implementation SignupTableViewController
#synthesize cellExaminername, cellExamineraddress, cellExaminercity, cellExaminerstate, cellExaminerzip, cellExamineremail, cellSearchthroughdate, cellTitleheldby, cellPropertyaddress1, cellPropertyaddress2, cellPropertycity, cellPropertystate, cellProperyzip, cellTitlesearchnotes;
#synthesize txtExaminername, txtExamineraddress, txtExaminercity, txtExaminerstate, txtExaminerzip, txtExamineremail, txtSearchthroughdate, txtTitleheldby, txtPropertyaddress1, txtPropertyaddress2, txtPropertycity, txtPropertystate, txtPropertyzip, txtTitlesearchnotes;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
UIBarButtonItem* btnSubmitSignup = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(#"Join",#"") style:UIBarButtonItemStylePlain target:self action:#selector(signup)];
[[self navigationItem] setRightBarButtonItem:btnSubmitSignup];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 14;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return cellExaminername;
}
if (indexPath.row == 1) {
return cellExamineraddress;
}
if (indexPath.row == 2) {
return cellExaminercity;
}
if (indexPath.row == 3) {
return cellExaminerstate;
}
if (indexPath.row == 4) {
return cellExaminerzip;
}
if (indexPath.row == 5) {
return cellExamineremail;
}
if (indexPath.row == 6) {
return cellSearchthroughdate;
}
if (indexPath.row == 7) {
return cellTitleheldby;
}
if (indexPath.row == 8) {
return cellPropertyaddress1;
}
if (indexPath.row == 9) {
return cellPropertyaddress2;
}
if (indexPath.row == 10) {
return cellPropertycity;
}
if (indexPath.row == 11) {
return cellPropertystate;
}
if (indexPath.row == 12) {
return cellProperyzip;
}
if (indexPath.row == 13) {
return cellTitlesearchnotes;
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
#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;
}
-(void) signup
{
// make sure the keyboard is hidden
[txtExaminername resignFirstResponder];
[txtExamineraddress resignFirstResponder];
[txtExaminercity resignFirstResponder];
[txtExaminerstate resignFirstResponder];
[txtExaminerzip resignFirstResponder];
[txtExamineremail resignFirstResponder];
[txtSearchthroughdate resignFirstResponder];
[txtTitleheldby resignFirstResponder];
[txtPropertyaddress1 resignFirstResponder];
[txtPropertyaddress2 resignFirstResponder];
[txtPropertycity resignFirstResponder];
[txtPropertystate resignFirstResponder];
[txtPropertyzip resignFirstResponder];
[txtTitlesearchnotes resignFirstResponder];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activityIndicator setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0+20)];
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
if (![self validateSignupForm])
return;
//do your signup code here
}
-(BOOL)validateSignupForm
{
BOOL rtn = YES;
// Declare your Alert, NSArray, increment int
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(#"FormIncomplete", #"") delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
NSArray *fieldArray;
int i = 0;
// Load up our field array with the UITextField Values
fieldArray = [NSArray arrayWithObjects:
[NSString stringWithFormat:#"%#",txtExaminername.text],
[NSString stringWithFormat:#"%#",txtExamineraddress.text],
[NSString stringWithFormat:#"%#",txtExaminercity.text],
[NSString stringWithFormat:#"%#",txtExaminerstate.text],
[NSString stringWithFormat:#"%#",txtExaminerzip.text],
[NSString stringWithFormat:#"%#",txtExamineremail],
[NSString stringWithFormat:#"%#",txtSearchthroughdate.text],
[NSString stringWithFormat:#"%#",txtTitleheldby.text],
[NSString stringWithFormat:#"%#",txtPropertyaddress1.text],
[NSString stringWithFormat:#"%#",txtPropertyaddress2.text],
[NSString stringWithFormat:#"%#",txtPropertycity.text],
[NSString stringWithFormat:#"%#",txtPropertystate.text],
[NSString stringWithFormat:#"%#",txtPropertyzip.text],
[NSString stringWithFormat:#"%#",txtTitlesearchnotes.text]];
// loop through the array, alert if text field is empty, and break the the loop, other wise increment i
for (NSString *fieldText in fieldArray){
NSLog(fieldText); // make sure all is reading correctly in the console
if([fieldText isEqualToString:#""]){
[alert show];
rtn = NO;
break; // break out!!
}
i++;
}
// check that all the field were passed (i == array.count)
//if(i == [[NSNumber numberWithInt: fieldArray.count] intValue]){
//NSLog(#"Passed validation...");
//rtn = YES;
// {
//if (rtn)
#end
Your -validateSignupForm method is missing a closing }.
A hint that this might be true is Xcode's desire to indent #end.