// update UI on main thread
dispatch_async(dispatch_get_main_queue(), ^{
//set cell need update
[self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded];
[self setNeedsLayout];
[self layoutIfNeeded];
//trying to get the tableview
id view = [self superview];
// different level of UITableView wrapping in different iOS version,
// for more detail please see:
// stackoverflow
while (view && [view isKindOfClass:[UITableView class]] == NO) {
view = [view superview];
}
if (view) {
UITableView *tableView = (UITableView *)view;
NSIndexPath *indexPath = [tableView indexPathForCell:self];
if (indexPath) {
[tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
}
});
2016年4月13日 星期三
Update UITableViewCell from itself
The code that can update the cell itself.
2016年4月11日 星期一
[JavaScript]Get XMLHttpRequest Traffic
Case: finding network traffic of a website, can't see relevant in the Console->network in Chrome, dig into code, it is XMLHttpRequest and not log in Console->Network
How: In console add hook into XMLHttpRequest
Code:
Source : http://stackoverflow.com/questions/16959359/intercept-xmlhttprequest-and-modify-responsetext
How: In console add hook into XMLHttpRequest
Code:
var rawOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
if (!this._hooked) {
this._hooked = true;
setupHook(this);
}
rawOpen.apply(this, arguments);
}
function setupHook(xhr) {
function getter() {
console.log('get responseText');
delete xhr.responseText;
var ret = xhr.responseText;
setup();
console.log('url : %s',xhr.responseURL);
console.log('ret : %s',ret);
return ret;
}
function setter(str) {
console.log('set responseText: %s', str);
}
function setup() {
Object.defineProperty(xhr, 'responseText', {
get: getter,
set: setter,
configurable: true
});
}
setup();
Source : http://stackoverflow.com/questions/16959359/intercept-xmlhttprequest-and-modify-responsetext
2016年4月4日 星期一
[iOS] UITableView scroll to top when typing in the textfield will scroll to a wrong location
My case is this:
I have a static table, with hidden cell(height = 0), custom cell that will open keyboard, and a reset button(that will reload table and scroll to top)
What is the problem:
Scroll to top will go to invalid offset.
How to regenerate:
type in the keyboard, reset(which scroll to top and reload the keyboard) and there will be space between my top cell and top of table (just like hidden cell consumed some space)
---
At first I thought it is the hidden cell problem, but it turns out to be problem on [tableView reloadData]
**[tableView reloadData] will interrupt scrolling, so make sure you call [tableView setContentOffset:] or [tableView scrollToRowAtIndexPath:] after all reload is done.
Reference: stackoverflow
I have a static table, with hidden cell(height = 0), custom cell that will open keyboard, and a reset button(that will reload table and scroll to top)
What is the problem:
Scroll to top will go to invalid offset.
How to regenerate:
type in the keyboard, reset(which scroll to top and reload the keyboard) and there will be space between my top cell and top of table (just like hidden cell consumed some space)
---
At first I thought it is the hidden cell problem, but it turns out to be problem on [tableView reloadData]
**[tableView reloadData] will interrupt scrolling, so make sure you call [tableView setContentOffset:] or [tableView scrollToRowAtIndexPath:] after all reload is done.
Reference: stackoverflow
訂閱:
文章 (Atom)