我的观点没有更新

时间:2014-02-14 00:30:12

标签: ios objective-c xml uitableview nsnumber

我的ParseXML方法读取NSNumber的值,只需点击一下按钮即可增加。

我的ParseXML方法有240个对象,每个对象的ID为1到30。

我的想法是,如果我将NSNumber从1增加到2,它会刷新我的视图并抓取与ID匹配的8个对象并在我的视图中显示它。

这正是没有做的事。

.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];
}

有什么建议吗?谢谢。我真的需要这个工作,所以我可以睡觉

1 个答案:

答案 0 :(得分:0)

您是否实现了UITableViewDelegate,UITableViewDataSource方法?

方法是:

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

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

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

您可以按照tutorial

进行操作