1

I have some issues in Today Extensions on iOS8. I tried debugging using the Xcode Debugger and by putting nslogs. There is no logic in my code as well. For some reason:

  1. The widget is not displaying any data (its only working for Hello World Label)
  2. Debugging is not working, it doesn't reach any break points. Is there any specific way to debug extensions?

Here is my code snippet

@implementation TodayViewController{
    NSArray *localList;
}

-(void)awakeFromNib{
    [super awakeFromNib];

    [self loadList];

    [self setPreferredContentSize:self.tableView.frame.size];

    NSLog(@"inside awake from nib");
}

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view.
   NSLog(@"inside view did load");
}

-(void)loadList{
    NSMutableArray *mutableArray = [[NSMutableArray alloc]initWithCapacity:5];
    [mutableArray addObject:@"asdjasdj"];
    [mutableArray addObject:@"qowiepqiw"];
    [mutableArray addObject:@"qoqwoei"];
    [mutableArray addObject:@"pqoiweoqi"];
    [mutableArray addObject:@"lkdsflk"];
    [mutableArray addObject:@"kdjlkaj"];

    localList = [mutableArray copy];
}

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

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

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

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WidgetCell"];

    UILabel *label = [[UILabel alloc]init];
    [label setText:[localList objectAtIndex:indexPath.row ]];
    [[cell contentView]addSubview:label];

    return cell; 
}
Andrew
  • 15,357
  • 6
  • 66
  • 101
Karthik
  • 934
  • 9
  • 21

4 Answers4

3

Write this

[self setPreferredContentSize:self.tableView.frame.size];

before loading any subview (tableview or label), and I write these in viewDidLoad. It works for me.

Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126
Janet
  • 31
  • 1
2

If the widget is not displaying, you can also try rebooting the phone.

Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88
1

To debug the extension, you need to manually attach the widget to the debugger.

From the Xcode menu "Debug" -> "Attach to process" -> "your extension bundle id"

Jing
  • 1,935
  • 3
  • 17
  • 26
  • Thanks. Is there a way in which i can get the make the debugger attached when the application is launched like it happens for the main app target? – Karthik Jun 20 '14 at 05:38
  • 1
    Not at the moment. Apple will look to do this in the next iteration of XCode is the latest word I have heard. – Ankush Agrawal Jul 10 '14 at 20:16
  • 1
    @AnkushAgrawal From the release note of Xcode 6 beta 3, it seems apple has fixed this problem. I haven't got a chance to verify this though. – Jing Jul 11 '14 at 02:07
0

Also make sure that the phone is unlocked if you're running it on a device. At least for me running the widget target won't unlock the phone but it works just fine if I do it myself.

Rick
  • 3,240
  • 2
  • 29
  • 53