Skip to content

Commit 893b8ea

Browse files
Fix not to assign self on some table view delegate methods.
1 parent a98a843 commit 893b8ea

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

Classes/Private/JSBMessageForwarding.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@ CGFloat tableViewHeightForRowAtIndexPath(id self, SEL _cmd, UITableView *tableVi
218218
JSValue *function = context[mangledNameFromClass(object_getClass(self))][JSBInstanceMembersKey][propertyName];
219219

220220
if (!function.isUndefined) {
221+
id currentSelf = context[@"self"];
222+
context[@"self"] = self;
223+
221224
JSValue *returnValue = [function callWithArguments:@[tableView, indexPath]];
225+
226+
context[@"self"] = currentSelf;
227+
222228
return returnValue.toDouble;
223229
}
224230

@@ -233,7 +239,13 @@ CGFloat tableViewHeightForHeaderInSection(id self, SEL _cmd, UITableView *tableV
233239
JSValue *function = context[mangledNameFromClass(object_getClass(self))][JSBInstanceMembersKey][propertyName];
234240

235241
if (!function.isUndefined) {
242+
id currentSelf = context[@"self"];
243+
context[@"self"] = self;
244+
236245
JSValue *returnValue = [function callWithArguments:@[tableView, @(section)]];
246+
247+
context[@"self"] = currentSelf;
248+
237249
return returnValue.toDouble;
238250
}
239251

@@ -248,7 +260,13 @@ CGFloat tableViewHeightForFooterInSection(id self, SEL _cmd, UITableView *tableV
248260
JSValue *function = context[mangledNameFromClass(object_getClass(self))][JSBInstanceMembersKey][propertyName];
249261

250262
if (!function.isUndefined) {
263+
id currentSelf = context[@"self"];
264+
context[@"self"] = self;
265+
251266
JSValue *returnValue = [function callWithArguments:@[tableView, @(section)]];
267+
268+
context[@"self"] = currentSelf;
269+
252270
return returnValue.toDouble;
253271
}
254272

Examples/UICatalog/UICatalog/UICatalog-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<key>UISupportedInterfaceOrientations</key>
3232
<array>
3333
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
3436
</array>
3537
</dict>
3638
</plist>

Examples/UICatalog/UICatalog/js/twitterViewController.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
var TwitterCell = JSB.defineClass('TwitterCell : UITableViewCell', {
22
initWithStyleReuseIdentifier: function(style, reuseIdentifier) {
3+
self.autoresizingMask = (1 << 1 | 1 << 4);
4+
35
self.iconImageView = UIImageView.alloc().initWithFrame({x: 8, y: 8, width: 40, height: 40});
46
self.iconImageView.tag = 1;
57
self.contentView.addSubview(self.iconImageView);
68

79
self.usernameLabel = UILabel.new();
10+
self.usernameLabel.autoresizingMask = (1 << 1);
811
self.usernameLabel.frame = {x: 56, y: 2, width: 254, height: 18};
912
self.usernameLabel.font = UIFont.systemFontOfSize(12);
1013
self.usernameLabel.textColor = UIColor.lightGrayColor();
1114
self.usernameLabel.tag = 2;
1215
self.contentView.addSubview(self.usernameLabel);
1316

1417
self.tweetLabel = UILabel.new();
18+
self.tweetLabel.autoresizingMask = (1 << 1 | 1 << 4);
1519
self.tweetLabel.frame = {x: 56, y: 20, width: 254, height: 40};
1620
self.tweetLabel.font = UIFont.systemFontOfSize(14);
1721
self.tweetLabel.textColor = UIColor.blackColor();
@@ -28,6 +32,7 @@ var TwitterViewController = JSB.defineClass('TwitterViewController : UITableView
2832
self.timeline = [];
2933

3034
self.sizeLabel = UILabel.alloc().initWithFrame({x: 0, y: 0, width: 268, height: 0});
35+
self.sizeLabel.autoresizingMask = (1 << 1 | 1 << 4);
3136
self.sizeLabel.font = UIFont.systemFontOfSize(14);
3237
self.sizeLabel.numberOfLines = -1;
3338

@@ -84,11 +89,8 @@ var TwitterViewController = JSB.defineClass('TwitterViewController : UITableView
8489
}
8590
});
8691
},
87-
shouldAutorotate: function() {
88-
return false;
89-
},
90-
supportedInterfaceOrientations: function() {
91-
return 1 << 1;
92+
didRotateFromInterfaceOrientation: function(fromInterfaceOrientation) {
93+
self.tableView.reloadData();
9294
},
9395
numberOfSectionsInTableView: function(tableView) {
9496
return 1;
@@ -100,7 +102,7 @@ var TwitterViewController = JSB.defineClass('TwitterViewController : UITableView
100102
var tweet = self.timeline[indexPath.row];
101103

102104
self.sizeLabel.text = tweet['text'];
103-
var size = self.sizeLabel.sizeThatFits({width: 254, height: 0});
105+
var size = self.sizeLabel.sizeThatFits({width: tableView.bounds.width - 66, height: 0});
104106

105107
return Math.max(size.height + 24, 80);
106108
},
@@ -116,7 +118,7 @@ var TwitterViewController = JSB.defineClass('TwitterViewController : UITableView
116118
var tweetLabel = cell.contentView.viewWithTag(3);
117119
tweetLabel.text = tweet['text'];
118120
var frame = tweetLabel.frame;
119-
frame.width = 254;
121+
frame.width = tableView.bounds.width - 66;
120122
tweetLabel.frame = frame;
121123
tweetLabel.sizeToFit();
122124

0 commit comments

Comments
 (0)