Karthik
Karthik

Reputation: 932

Today Extension not working

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

Upvotes: 1

Views: 3527

Answers (4)

Janet
Janet

Reputation: 31

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.

Upvotes: 3

Lim Thye Chean
Lim Thye Chean

Reputation: 9434

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

Upvotes: 2

Richard
Richard

Reputation: 3296

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.

Upvotes: 0

Jing
Jing

Reputation: 1965

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"

Upvotes: 1

Related Questions