小编Roo*_*Roo的帖子

NSURLConnection在另一个线程中开始.委托方法未调用

我在另一个线程中启动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

5
推荐指数
1
解决办法
2472
查看次数

向上滚动时StaggeredGridLayout会混乱

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

5
推荐指数
1
解决办法
2867
查看次数

带有redux的React-Native-Navigation V2无法通过道具

我有一个简单的两屏应用程序,其中包含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

5
推荐指数
1
解决办法
966
查看次数

字节签名短

我得到两个字节,例如0xFE和0x70,它应该代表-400的值.我怎么能把这些字节转换成有符号的短?它甚至可能吗?

c# c++

0
推荐指数
2
解决办法
228
查看次数