user726799
user726799

Reputation: 1

iPhone own class in array, out of scope

i have created my own class, calles cls_myClass.

**cls_myClass.h**

@interface cls_myClass : NSObject {
  NSString *i_something;
}
@property (nonatomic, retain) NSString *i_something;
-(NSString *) get_something;
@end

In my RootViewController I have got a timer, an array and a tableview.

**RootViewController.h**

@interface RootViewController : UITableViewController {
   MSMutableArray *i_array;
   NSTimer *i_timer;
}
...
@end

Now I add on the timerintervall some new values to the i_array:

**RootViewController.m**
cls_myClass *dummy = [[cls_myClass alloc] init];
[dummy addSomething:@"test"];

[i_array addObject: dummy];
[self.tableView reloadData];

the function -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection returns the correct number of items from i_array

Now I want to get the Items from i_array and put them into the tableView

**RootViewController.m**
- (UITableViewCell *)tableView(UITableview *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
//...

int *max = [i_array count];
int *idx = indexPath.row;

cls_myClass *dummy = [i_array objectAtIndex:idx];

NSString *something = [dummy get_something];
}

The problem is, that the var something is out of scope, but I don't know why...

maybe someone can help me? :)

thanks hibbert

Upvotes: 0

Views: 83

Answers (1)

Chetan Bhalara
Chetan Bhalara

Reputation: 10344

Use

int max = [i_array count];
int idx = indexPath.row;

Instead of

int *max = [i_array count];
int *idx = indexPath.row;

You should read this : http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html

Upvotes: 1

Related Questions