Pass parameter during table initialization

Well, I'm completely stumped here.

This works in CouponListViewController.m:

- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.couponList = [CouponDatabase database].couponList; self.title = @"Coupon List"; } 

And this works in CouponDetailViewController.m:

 - (void)viewWillAppear:(BOOL)animated { CouponDetails *details = [[CouponDatabase database] couponDetails:_uniqueId]; if (details != nil) { [_merchantNameLabel setText:details.merchantName]; [_longDealLine1Label setText:details.longDealLine1]; //....blah...blah// } } 

But when I change CouponDatabase.h from this (which works with the above):

 @class CouponDetails; @interface CouponDatabase : NSObject { sqlite3 *_database; } + (CouponDatabase *)database; - (NSArray *)couponList; - (CouponDetails *)couponDetails:(int) uniqueId; 

... to this (which works if I manually set the value "selectedCategory" inside the method):

 @class CouponList; @class CouponDetails; @interface CouponDatabase : NSObject { sqlite3 *_database; } + (CouponDatabase *)database; - (CouponList *)couponList:(int) selectedCategory; - (CouponDetails *)couponDetails:(int) uniqueId; 

and then change CouponListViewController.m to:

 1 - (void)viewWillAppear:(BOOL)animated { 2 [super viewWillAppear:animated]; 3 self.couponList = [[CouponDatabase database] couponList:_selectedCategory]; 4 self.title = @"Coupon List"; 5 } 

I get this error on line 3 above:

 warning: incompatible Objective-C types 'struct CouponList *', expected 'struct NSArray *' when passing argument 1 of 'setCouponList:' from distinct Objective-C type 

Question: What is the proper formatting of the self.couponlist string so that I can pass an integer to the coupon database for use in the couponList method?

EDIT: I know couponDetails is now a class instead of an array - I just don't know how to format a row to initialize table data.

I hope this makes sense - any help in this would be greatly appreciated.

Thanks in advance!

Adding CouponListViewController.h:

 #import <UIKit/UIKit.h> @class CouponDetailsViewController; @interface CouponListViewController : UITableViewController { NSArray *_couponList; CouponDetailsViewController *_couponDetails; int _selectedCategory; } @property (nonatomic, retain) NSArray *couponList; @property (nonatomic, retain) CouponDetailsViewController *couponDetails; @property(nonatomic, assign) int selectedCategory; @end 
0
source share
2 answers

Try changing your CouponListViewController.h to the following:

 #import <UIKit/UIKit.h> @class CouponDetailsViewController; @interface CouponListViewController : UITableViewController { CouponList *_couponList; CouponDetailsViewController *_couponDetails; int _selectedCategory; } @property (nonatomic, retain) CouponList *couponList; @property (nonatomic, retain) CouponDetailsViewController *couponDetails; @property(nonatomic, assign) int selectedCategory; @end 

Unfortunately, I put my answer in my own original post and should have indicated it here:

Edit: Well, I made changes to CouponListViewController.h, as Robert recommended, plus added @class CouponList; in the following way:

 #import <UIKit/UIKit.h> @class CouponList; @class CouponDetailsViewController; @interface CouponListViewController : UITableViewController { CouponList *_couponList; CouponDetailsViewController *_couponDetails; int _selectedCategory; } @property (nonatomic, retain) CouponList *couponList; @property (nonatomic, retain) CouponDetailsViewController *couponDetails; @property(nonatomic, assign) int selectedCategory; @end 

I still get errors in CouponListViewController.m:

 #import "CouponListViewController.h" #import "CouponDatabase.h" #import "CouponList.h" #import "CouponDetailsViewController.h" @implementation CouponListViewController @synthesize couponList = _couponList; @synthesize couponDetails = _couponDetails; @synthesize selectedCategory = _selectedCategory; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.couponList = [CouponDatabase database].couponList; // <--- ERROR 1 self.title = @"Coupon List"; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_couponList count]; // <--- WARNINGS 1 AND 2 } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.couponDetails == nil) { self.couponDetails = [[[CouponDetailsViewController alloc] initWithNibName:@"CouponDetailsViewController" bundle:nil] autorelease]; } CouponList *info = [_couponList objectAtIndex:indexPath.row]; // <--- WARNING 3 NSLog(@"%@", info.uniqueId); _couponDetails.uniqueId = info.uniqueId; [self.navigationController pushViewController:_couponDetails animated:YES]; } 

ERROR 1: query for member 'couponList' in something not structure or union

WARNING 1: "Coupon List" may not respond to "-count"

WARNING 2: return makes an integer from a pointer without cast

WARNING 3: "CouponList" may not respond to "-AtIndex:"

0
source

In the source code for CouponDatabase, you change the definition:

 - (NSArray *)couponList; 

for this:

 - (CouponList *)couponList:(int) selectedCategory; 

However, you are using this return value as the data source for the list controller, so. Here you have a discrepancy that you must correct. How to fix this depends on the semantics of your application. What are you trying to do with - (CouponList *)couponList:(int) selectedCategory; ? What does this selector really return? What is the CouponList interface? Perhaps you should change the line:

  self.couponList = [[CouponDatabase database] couponList:_selectedCategory]; 

so that it returns the NSArray assembly from CouponList . But I'm not sure about the semantics of your objects, so this may not be the case.

0
source

All Articles