我有两个自定义UICollectionViewCells(import * as React from 'react'
import {Button, createMuiTheme, Paper} from '@material-ui/core'
import {createGenerateClassName, createStyles, makeStyles, StylesProvider, ThemeProvider, withStyles} from '@material-ui/styles'
export const theme = createMuiTheme({
palette: {
primary: {
light: '#aabddc',
main: '#518aba',
dark: '#004a98',
},
secondary: {
light: '#c5ddb8',
main: '#8bbd74',
dark: '#4c9c2e',
},
error: {
light: '#f9b3b6',
main: '#f2686d',
dark: '#ec1c24',
},
},
typography: {
fontFamily: 'roboto, sans-serif',
},
})
const styles = makeStyles(() => {
const color1 = '#ff9955'
const color2 = '#d0a0ff'
const color3 = '#a0d0ff'
return createStyles({
'@global': {
'button.spaced': {
margin: '5px',
},
'.mesButton': {
backgroundColor: color1,
'&:hover': {
backgroundColor: color1,
},
},
'.mesButton:hover': {
filter: 'brightness(85%)',
},
'.mesButtonDark': {
backgroundColor: color2,
'&:hover': {
backgroundColor: color2,
},
},
'.mesButtonLight': {
backgroundColor: color3,
'&:hover': {
backgroundColor: color3,
},
},
},
})
})
const generateClassName = createGenerateClassName({
disableGlobal: true,
productionPrefix: '', // maybe 'mes'
})
export interface AnalysisSelectorProps {
refreshOnSettingsChange: boolean
previousDrillDownEnabled: boolean
message: string
drillDownBreadCrumb: string
showMessage: boolean
}
export interface AnalysisSelectorState {
clicks: number
}
export class InnerAnalysisSelector extends React.Component<AnalysisSelectorProps, AnalysisSelectorState> {
public static defaultProps: Partial<AnalysisSelectorProps> = {
refreshOnSettingsChange: false,
previousDrillDownEnabled: false,
message: '',
drillDownBreadCrumb: '',
showMessage: true,
}
state: AnalysisSelectorState = {
clicks: 0,
}
render() {
return (
<ThemeProvider theme={theme}>
<StylesProvider generateClassName={generateClassName}>
<Paper className={'paperContainer'}>
<Button className={'mesButton mesButtonLight spaced'}>Add</Button>
<Button className={'mesButton spaced'}>Subtract</Button>
<Button className={'mesButton mesButtonDark spaced'}>5x</Button>
<Button variant='contained' color='primary' className='spaced'>Reset</Button>
<br />
<div>Number of clicks: {this.state.clicks}</div>
</Paper>
</StylesProvider>
</ThemeProvider>
)
}
}
export const AnalysisSelector = withStyles(styles)(InnerAnalysisSelector)
,AddImageCollectionViewCell
),我将根据索引路径进行加载。这是我的ItemCollectionViewCell
-
cellForItemAtIndexpath
我得到的错误是“ UICollectionViewCell类型的值?”没有成员“ contentImage””。为什么else子句中的单元格未转换为“ ItemCollectionViewCell”类型。
我知道,我必须做一些非常愚蠢的事情。如果有人能指出我正确的方向,我将不胜感激。
答案 0 :(得分:2)
您将cell
声明为基本类型UICollectionViewCell
,这就是原因。分别返回细胞
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "addImageCell", for: indexPath) as! AddImageCollectionViewCell
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath) as! ItemCollectionViewCell
cell.contentImage = self.droppedItemList[indexPath.row]
return cell
}
}