我在另一个线程中启动NSURLConnection:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),
^{
NSURLConnection *connection = [NSURLConnection connectionWithRequest:[request preparedURLRequest] delegate:self];
[connection start];
});
Run Code Online (Sandbox Code Playgroud)
但是我的委托方法没有被调用:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data;
Run Code Online (Sandbox Code Playgroud)
在主线程上运行时一切都很好.如何在另一个线程上运行连接并获取在同一线程上调用的委托方法?
multithreading objective-c nsurlconnection grand-central-dispatch ios
我StaggeredGridLayout为我做了这个RecyclerView:

这是代码:
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
Photo photo = mPhotos.get(position);
TextView titleView = ((CellViewHolder) viewHolder).titleTextView;
titleView.setText(photo.getTitle());
TextView subTitleView = ((CellViewHolder) viewHolder).subtitleTextView;
subTitleView.setText(photo.getName());
Picasso.with(mContext).load(photo.getPhotoUrl()).into(((CellViewHolder) viewHolder).imageView);
ImageView userImageOverlay = ((CellViewHolder) viewHolder).userImageOverlay;
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
if (position == 0 || position % 4 == 0) {
layoutParams.setFullSpan(true);
layoutParams.height = Math.round(Utils.convertDpToPixel(202.67f, mContext));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21.67f);
subTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12.00f);
userImageOverlay.setVisibility(View.VISIBLE);
} else if ((position - 1) % 4 == 0) {
layoutParams.setFullSpan(false);
layoutParams.height = Math.round(Utils.convertDpToPixel(360.00f, mContext)); …Run Code Online (Sandbox Code Playgroud) android staggered-gridview recycler-adapter android-recyclerview
我有一个简单的两屏应用程序,其中包含redux和React-Native-Navigation V2。我尝试将项目从列表传递到另一个视图作为道具。不幸的是,我得到一个错误:
TypeError:无法读取未定义的属性“ id”
该项目已通过但未在第二视图中作为道具被接收。在没有Redux的情况下,一切正常。我是否正确注册了视图?
查看注册:
export default (store) => {
Navigation.registerComponent('example.app.FirstScreen', reduxStoreWrapper(FirstScreen, store));
Navigation.registerComponent('example.app.SecondScreen', reduxStoreWrapper(SecondScreen, store));
}
function reduxStoreWrapper (MyComponent, store) {
return () => {
return class StoreWrapper extends React.Component {
render () {
return (
<Provider store={store}>
<MyComponent />
</Provider>
);
}
};
};
}
Run Code Online (Sandbox Code Playgroud)
第一视图:
class FirstScreen extends Component {
componentDidMount() {
this.props.listItems();
}
onItemPress = (item: Item) => {
Navigation.push(item._id, {
component: {
name: 'example.app.SecondScreen',
passProps: {
item: item
}
}
});
};
render() { …Run Code Online (Sandbox Code Playgroud) react-native redux react-native-navigation wix-react-native-navigation react-native-navigation-v2