0

Okay, I'm totally 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 the 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 of '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 this:

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' line so that I can pass an integer to the CouponDatabase for use in the couponList method?

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

I hope this makes sense - any help on this would be very 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
truthsmiles
  • 136
  • 6

2 Answers2

0

Try changing your CouponListViewController.h to this:

#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

Oops I put my response in my own original post and should have put it here:

Edit: Okay, I made changes to CouponListViewController.h as recommended by Robert, plus added @class CouponList; as follows:

#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'm still getting 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: request for member 'couponList' in something not a structure or union

WARNING 1: 'CouponList' may not respond to '-count'

WARNING 2: return makes integer from pointer without a cast

WARNING 3: 'CouponList' may not respond to '-objectAtIndex:'

truthsmiles
  • 136
  • 6
Robert Kovačević
  • 1,378
  • 4
  • 16
  • 23
0

In you original code for CouponDatabase, you are changing the definition:

- (NSArray *)couponList;

for this one:

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

Nevertheless, you use that return value as datasource for a list view controller, so . Here you have a mismatch you should fix. How to fix it depends on the semantics of your application. What are your trying to do with - (CouponList *)couponList:(int) selectedCategory;? What does really return this selector? What is the interface CouponList? Possibly you should change the line:

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

so that it returns an NSArray build from a CouponList. But I am not sure of the semantics of your objects, so this might not be the case.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • Thanks Sergio - Okay I made the change you suggested, and it got rid of the error, but the 3 warnings are still there. I will try to investigate and figure it out. I'm not sure I understand your question, but I am trying to set "selectedCategory" with a button press, then pass that to CouponList so that it returns a list based on the button that was pressed, and presents it in a table view. thank you so much for looking at my problem! – truthsmiles Jun 06 '11 at 13:22
  • @truthsmiles: actually, I have not suggested any change. I was pointing at a mismatch. :-) what change did you make exactly? – sergio Jun 06 '11 at 13:33
  • Haha - sorry - I made the change to: self.couponList = [[CouponDatabase database] couponList:_selectedCategory]; I feel like this is on the right track, and you got me over a significant hurdle - now I just need to study more. By the way, in parallel, I'm working on another "test" app to have a UIViewController with custom buttons that when pressed will reveal the correct tableview. I just solved that, so all I need to do is figure out how to pass the parameter from the button to the tableview and I'll be in great shape! Thanks for your help! You guys are all so great! – truthsmiles Jun 06 '11 at 14:02