2011-06-26 50 views
-2

我宣佈了一個NSMutable數組併爲其分配了一些值。NSMutableArray問題

.h 
NSMutableArray *imageDetailsFromCategory; 

@property (nonatomic, retain) NSMutableArray *imageDetailsFromCategory; 

.m 
@synthesise imageDetailsFromCategory 
在viewDidLoad中

imageDetailsFromCategory = [[NSMutableArray alloc]init]; 

//assigning object to Array..working fine.showing two images. 
imageDetailsFromCategory = [self getImageDetailsFromCategory:generatedString]; 

我有,現在解決的一個問題。我有一個問題,那就是我將這個數組傳遞給StaticCategoryWithMultiImagePopOver類。

StaticCategoryWithMultiImagePopOver *staticCategoryWithMultiImagePopOver = [[StaticCategoryWithMultiImagePopOver alloc] init]; 

[staticCategoryWithMultiImagePopOver setParentImageDetailsArray:imageDetailsFromCategory]; 
在StaticCategoryWithMultiImagePopOver.h

NSMutableArray *nsmResult; 
@property (nonatomic,retain)NSMutableArray *nsmResult; 

的.m

@synthesize nsmResult 

-(void)setParentImageDetailsArray:(NSMutableArray *)imageDetailsFromCategoryFromParent{ 
    nsmResult=[[NSMutableArray alloc] init]; 
    nsmResult=[imageDetailsFromCategoryFromParent retain]; 

    } 

傳遞的數組保持與每個索引處一些字符串變量類對象。

所以我通過代碼收到此:

- (UITableViewCell *)tableView:(UITableView *)tableView15 cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 


    UITableViewCell *cell = [tableView15 dequeueReusableCellWithIdentifier:CellIdentifier]; 
    // if (cell == nil) { 
    // cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    // } 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager 


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it 


    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    SymbolTalkEntry *symbolTalkEntry = [[SymbolTalkEntry alloc]init]; 

    symbolTalkEntry =[nsmResult objectAtIndex:indexPath.row]; 

    NSString *imageNme = symbolTalkEntry.fileName; // *this line* 

上述行越來越錯誤。

陣列顯示計數,但對象是出scope..cant的獲取值...

任何一個可以告訴我,我怎麼能訪問它......可我知道是什麼問題我...

的cellForRowAtIndexPath(其工作的罰款)

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView15 cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 


    UITableViewCell *cell = [tableView15 dequeueReusableCellWithIdentifier:CellIdentifier]; 
    // if (cell == nil) { 
    // cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    // } 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager 


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it 


    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    SymbolTalkEntry *symbolTalkEntry = [[SymbolTalkEntry alloc]init]; 

    symbolTalkEntry =[nsmResult objectAtIndex:indexPath.row]; 

    NSString *imageNme = symbolTalkEntry.fileName; 

    [symbolTalkEntry release]; 
    //Display image from app bundle 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",imageNme]]; 

    cell.imageView.image= [UIImage imageWithContentsOfFile:path]; 
    return cell; 


} 

-(NSInteger)number 
+0

是StaticCategoryWithMultiImagePopOver您的表視圖數據源嗎?或者'cellForRowAtIndexPath'方法中的文件是什麼? – jtbandes

+2

爲什麼你總是'alloc init'如果你打算指向另一個對象之後呢? –

+0

@jtbandes:是的...... – Christina

回答

3

nsmResult=[[NSMutableArray alloc] init]; 
nsmResult=[imageDetailsFromCategoryFromParent retain]; 

SymbolTalkEntry *symbolTalkEntry = [[SymbolTalkEntry alloc]init]; 
symbolTalkEntry =[nsmResult objectAtIndex:indexPath.row]; 

是內存泄漏。

關於你的問題:你的

symbolTalkEntry =[nsmResult objectAtIndex:indexPath.row]; 

獲取對象似乎沒有屬性的文件名。

我認爲你應該閱讀一本關於Objective-C和Cocoa的好書。

0

其實這是在數組內的類的問題。

我改變了我的課,因爲這:

#import <Foundation/Foundation.h> 


@interface SymbolTalkEntry : NSObject { 

int categoryId; 
NSString *runModeType; 
NSString *sceneCategory; 
NSString *fileName; 
int isDefault; 
int sortX; 
int pathId;// 0 for appbundle 1 for document directry 


} 
@property (nonatomic, retain)NSString *runModeType;; 
@property (nonatomic, retain)NSString *sceneCategory; 
@property (nonatomic, retain)NSString *fileName; 

-(id)init; 

-(void) setCategoryId:(int) ctgId; 
-(int)categoryId; 

-(void) setRunModeType:(NSString *)rmType; 
-(NSString *) runModeType; 

-(void) setSceneCategory:(NSString *)scCategory; 
-(NSString *) sceneCategory; 

-(void) setFileName:(NSString *)Flname; 
-(NSString *) fileName; 

-(void) setIsDefault:(int) isDeft; 
-(int)isDefault; 

-(void) setSortX:(int) srtX; 
-(int)sortX; 

-(void) setPathId:(int) srtX; 
-(int)pathId; 
@end 
[5:05:00 AM] Shamsudheen TK: #import "SymbolTalkEntry.h" 


@implementation SymbolTalkEntry 
@synthesize runModeType; 
@synthesize sceneCategory; 
@synthesize fileName; 


-(id) init{ 
categoryId = 0; 
runModeType = @""; 
sceneCategory [email protected]""; 
fileName = @""; 
isDefault = 0; 
sortX =0; 
pathId =0; 
return self; 
} 
-(void) setCategoryId:(int) ctgId{ 
categoryId = ctgId; 
} 
-(int)categoryId{ 
return categoryId; 
} 

-(void) setRunModeType:(NSString *)rmType{ 

if (runModeType != rmType) { 
    [runModeType release ]; 
    runModeType = [rmType retain]; 
} 
} 
-(NSString *) runModeType{ 
return runModeType; 
} 

-(void) setSceneCategory:(NSString *)scCategory{ 

if (sceneCategory != scCategory) { 
    [sceneCategory release]; 
    sceneCategory = [scCategory retain]; 
} 
} 
-(NSString *) sceneCategory{ 
return sceneCategory; 
} 

-(void) setFileName:(NSString *)Flname{ 

if (fileName != Flname) { 
    [fileName release]; 
    fileName = [Flname retain]; 
} 
} 
-(NSString *) fileName{ 
return fileName; 
} 

-(void) setIsDefault:(int) isDeft{ 
isDefault = isDeft; 
} 
-(int)isDefault{ 
return isDefault; 
} 

-(void) setSortX:(int) srtX{ 
sortX =srtX; 
} 
-(int)sortX{ 
return sortX; 
} 

-(void) setPathId:(int) srtX{ 
pathId = srtX; 
} 
-(int)pathId{ 
return pathId; 
} 

-(void)dealloc{ 
[categoryId release]; 
[runModeType release]; 
[sceneCategory release]; 
[fileName release]; 
[isDefault release]; 
[sortX release]; 
[pathId release]; 
} 
@end 

,並設置使用我寫的設置方法的值(例如:[classobj setCategoryId:1])。

現在超出範圍解決.....