开发者

iPhone own class in array, out of scope

i have created my own class, calles cls_myClass.

**cls_myClass.h**

@interface cls开发者_Go百科_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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜