2014-10-30 3 views
1

Я пытаюсь добавить сегодня расширение, которое показывает список из RSS-канала, как то, что делает мое приложение. Моя проблема в том, что он не показывает данные.Сегодня расширение виджета, не отображающее данные

.h

#import <UIKit/UIKit.h> 

@class RSSChannel; 

@interface TodayViewController : UIViewController <NSXMLParserDelegate, UITableViewDataSource, UITableViewDelegate> { 
    NSURLConnection *connection; 
    NSMutableData *xmlData; 
    RSSChannel *channel; 
} 

@property (weak, nonatomic) IBOutlet UITableView *widgetTableView; 

- (void)fetchEntries; 

@end 

.m

#import "TodayViewController.h" 
#import "RSSChannel.h" 
#import "RSSItem.h" 
#import <NotificationCenter/NotificationCenter.h> 

@interface TodayViewController() <NCWidgetProviding> 

@end 

@implementation TodayViewController 

@synthesize widgetTableView; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    [self fetchEntries]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler { 
    // Perform any setup necessary in order to update the view. 

    // If an error is encountered, use NCUpdateResultFailed 
    // If there's no update required, use NCUpdateResultNoData 
    // If there's an update, use NCUpdateResultNewData 

    completionHandler(NCUpdateResultNewData); 
} 

- (void)fetchEntries 
{ 
    xmlData = [[NSMutableData alloc]init]; 

    NSURL *url = [NSURL URLWithString:@"http://kyfbnewsroom.com/category/ag-news/feed"]; 

    NSURLRequest *req = [NSURLRequest requestWithURL:url]; 

    connection = [[NSURLConnection alloc]initWithRequest:req delegate:self startImmediately:YES]; 
} 

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{ 
    if ([elementName isEqual:@"channel"]) 
    { 
     channel = [[RSSChannel alloc]init]; 

     [channel setParentParserDelegate:self]; 

     [parser setDelegate:channel]; 
    } 
} 

- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data 
{ 
    [xmlData appendData:data]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)conn 
{  
    NSXMLParser *parser = [[NSXMLParser alloc]initWithData:xmlData]; 

    [parser setDelegate:self]; 

    [parser parse]; 

    xmlData = nil; 

    NSMutableArray *actionAlerts = [NSMutableArray array]; 

    for (RSSItem *object in channel.items) 
    { 
     if (object.isActionAlert) 
     { 
      [actionAlerts addObject:object]; 
     } 
    } 

    for (RSSItem *object in actionAlerts) 
    { 
     [channel.items removeObject:object]; 
    } 

    // Reload the table 
    [[self widgetTableView]reloadData]; 
} 

- (void)connection:(NSURLConnection *)conn didFailWithError:(NSError *)error 
{ 
    connection = nil; 

    xmlData = nil; 
} 

# pragma mark - Table View Delegate Methods 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [[channel items]count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    RSSItem *item = [[channel items]objectAtIndex:[indexPath row]]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 
     cell.textLabel.font = [UIFont systemFontOfSize:16.0]; 
    } 

    if (cell) { 
     cell.textLabel.text = [item title]; 
     cell.textLabel.textColor = [UIColor clearColor]; 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.backgroundColor = [UIColor clearColor]; 
    } 

    return cell; 
} 

@end 

enter image description here

ответ

0

Вы не должны очистить цвет текста текста ярлыка в Tableview: cellForRowAtIndexPath метод делегата. Попробуйте назначить, например. белый цвет:

cell.textLabel.textColor = [UIColor whiteColor]; 
Смежные вопросы