我有一个TableView,在UITableViewCell中我有一个UICollectionView。 现在在我的collectionView中,对于每个collectionViewCell,都有一个创建单元格和删除单元格按钮选项。因此,对于创建单元格,我必须使用CreateViewController,对于删除按钮,我必须删除各自的collectionViewCell。
import UIKit
class TableCollectionCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
//collectionView cell
collectionView!.register(UINib(nibName: "CreateGroupCell", bundle: nil), forCellWithReuseIdentifier: "CreateGroupCell")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
//Collection View
extension TableCollectionCell : UICollectionViewDataSource ,UICollectionViewDelegateFlowLayout
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CreateGroupCell", for: indexPath) as! CreateGroupCell
cell.groupName.text = ""
CreateCardView(viewCorner: cell.cardView)
if(0 == indexPath.row)
{
//cell.btnDotted.tag = indexPath.row
//cell.btnShare.tag = indexPath.row
cell.btnDotted.setImage(UIImage(named: "Info"), for: UIControlState.normal)
cell.btnShare.setImage(UIImage(named : "AddGroup"), for: UIControlState.normal)
}
else if(indexPath.row >= 1 && indexPath.row <= 3)
{
cell.btnDotted.isHidden = true
cell.btnShare.isHidden = true
cell.groupImage.image = UIImage(named: "group_dull_card.png")
}
else
{
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if ( 0 == indexPath.row) {
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200, height: 150)
}
}
现在在我的didSelectRow方法if(indexPath.row == 0)然后我必须去CreateViewController。
我该怎么做?我也是代表的新人。
答案 0 :(得分:0)
didSelectRow方法
ViewPager viewPager;
ViewPagerAdapter adapter;
viewPager = (ViewPager) findViewById(R.id.tabanim_viewpager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabanim_tabs);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabanim_tabs);
setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
adapter.getItem(position).onResume();
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
public void setupViewPager(ViewPager upViewPager) {
adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new ViewTodayFragment(),"Daily");
adapter.addFrag(new ViewWeekFragment(),"Weekly");
adapter.addFrag(new ViewMonthFragment(),"Monthly");
adapter.addFrag(new ViewYearFragment(),"Yearly");
viewPager.setAdapter(adapter);
}