2014-02-14 34 views
0

我的ParseXML方法讀取NSNumber的值,它可以通過點擊一個按鈕來增加。我的看法沒有更新

我ParseXML方法具有240個對象,每個8具有從1至30

的想法是,如果i從1到2遞增的NSNumber,它刷新我的視圖,並抓住匹配的8個對象的ID該ID並將其顯示在我的視圖中。

這正是沒有做的。

.h 

@interface FixturesController : UITableViewController 
{ 
    NSMutableData *_responseDataFixtures; 
    int goUp; 
    NSNumber *test; 
} 

@property (nonatomic, retain) NSArray *tableDataFixtures; 
@property (nonatomic, strong) NSMutableArray *roundParser; 
@property (nonatomic, strong) NSString *seasonRoundString; 
@property (nonatomic, strong) NSNumber *seasonRoundNumber; 

- (IBAction)goUpByOne:(UIButton *)sender; 

-(void) parseXMLFixtures:(NSNumber *) giveME; 



@end 


.m 


- (void) viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 
    [self parseXMLFixtures:@2]; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    goUp = 1; 
    test = [NSNumber numberWithInt:goUp]; 

} 

// this allows me to increment the count of NSNumber. 
- (IBAction)goUpByOne:(UIButton *)sender { 

    goUp++; 

    test = [NSNumber numberWithInt:goUp]; 

    goUp = [test intValue]; 

} 


-(void) parseXMLFixtures:(NSNumber *) giveME 
{ 

    giveME = test; 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"There's no going back"]]; 

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

    NSString *xmlString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 

    NSDictionary *xml = [NSDictionary dictionaryWithXMLString:xmlString]; 

    NSMutableArray *items = [xml objectForKey:@"Match"]; 

    NSMutableArray *newFixtureObjectArray = [[NSMutableArray alloc] init]; 

    NSNull *nullValue = [NSNull null]; 

    [newFixtureObjectArray insertObject:nullValue atIndex:0]; 
    [newFixtureObjectArray insertObject:nullValue atIndex:1]; 

    for (NSDictionary *dict in items) { 
     FixturesObject *myFixtures = [FixturesObject fixtureFromXMLDictionary:dict]; 
     [newFixtureObjectArray addObject:myFixtures]; 
    } 

    /////// 

    _seasonRoundString = [NSString stringWithFormat:@"%d", [giveME intValue]]; 
    _roundParser = [[NSMutableArray alloc]init]; 

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"round == %@", _seasonRoundString]; 
    NSArray *filteredArray = [newFixtureObjectArray filteredArrayUsingPredicate:predicate]; 
    _roundParser = [NSMutableArray arrayWithArray:filteredArray]; 
    [_roundParser insertObject:nullValue atIndex:0]; 

    NSLog(@" Objects of Fixtures in my array %@", _roundParser); 

    ///// 

    [self setTableDataFixtures:_roundParser]; 
} 

有什麼建議嗎?謝謝。我真的需要這個工作,所以我可以去睡

+0

你嘗試的'viewDidAppear'代替'viewWillAppear'? – Lexicon

回答

0

你是否已經實現了UITableViewDelegate,UITableViewDataSource方法呢?

的方法是:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ } 

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

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{} 

你可以按照這個tutorial